aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/auth.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2011-04-21 23:15:51 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2011-04-21 23:15:51 -0400
commitf49656986cc1898e85d6d7e4cd859ec8e980dc4a (patch)
tree6386ebf3247192cb477510d25fa2a1cf2da6c20d /phpBB/includes/auth.php
parentb1367bce488d0acea00a5ebf8725d0cde5515655 (diff)
downloadforums-f49656986cc1898e85d6d7e4cd859ec8e980dc4a.tar
forums-f49656986cc1898e85d6d7e4cd859ec8e980dc4a.tar.gz
forums-f49656986cc1898e85d6d7e4cd859ec8e980dc4a.tar.bz2
forums-f49656986cc1898e85d6d7e4cd859ec8e980dc4a.tar.xz
forums-f49656986cc1898e85d6d7e4cd859ec8e980dc4a.zip
[ticket/10141] Save a hash lookup when value is not in cache.
PHPBB3-10141
Diffstat (limited to 'phpBB/includes/auth.php')
-rw-r--r--phpBB/includes/auth.php10
1 files changed, 7 insertions, 3 deletions
diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php
index 4b13c6be7f..8324cb4977 100644
--- a/phpBB/includes/auth.php
+++ b/phpBB/includes/auth.php
@@ -126,13 +126,17 @@ class auth
while ($subseq = substr($seq, $i, 6))
{
- if (!isset($seq_cache[$subseq]))
+ if (isset($seq_cache[$subseq]))
{
- $seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);
+ $converted = $seq_cache[$subseq];
+ }
+ else
+ {
+ $converted = $seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);
}
// We put the original bitstring into the acl array
- $this->acl[$f] .= $seq_cache[$subseq];
+ $this->acl[$f] .= $converted;
$i += 6;
}
}
d='n176' href='#n176'>176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';

class phpbb_request_var_test extends phpbb_test_case
{
	/**
	* Makes sure request_var has its standard behaviour.
	*/
	protected function setUp()
	{
		parent::setUp();
		request_var(false, false, false, false, false);
	}

	/**
	* @dataProvider request_variables
	*/
	public function test_post($variable_value, $default, $multibyte, $expected)
	{
		$variable_name = 'name';
		$this->unset_variables($variable_name);

		$_POST[$variable_name] = $variable_value;
		$_REQUEST[$variable_name] = $variable_value;

		$result = request_var($variable_name, $default, $multibyte);

		$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
		$this->assertEquals($expected, $result, $label);
	}

	/**
	* @dataProvider request_variables
	*/
	public function test_get($variable_value, $default, $multibyte, $expected)
	{
		$variable_name = 'name';
		$this->unset_variables($variable_name);

		$_GET[$variable_name] = $variable_value;
		$_REQUEST[$variable_name] = $variable_value;

		$result = request_var($variable_name, $default, $multibyte);

		$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
		$this->assertEquals($expected, $result, $label);
	}

	/**
	* @dataProvider request_variables
	*/
	public function test_cookie($variable_value, $default, $multibyte, $expected)
	{
		$variable_name = 'name';
		$this->unset_variables($variable_name);

		$_GET[$variable_name] = false;
		$_POST[$variable_name] = false;
		$_REQUEST[$variable_name] = false;
		$_COOKIE[$variable_name] = $variable_value;

		$result = request_var($variable_name, $default, $multibyte, true);

		$label = 'Requesting COOKIE variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
		$this->assertEquals($expected, $result, $label);
	}

	/**
	* Helper for unsetting globals
	*/
	private function unset_variables($var)
	{
		unset($_GET[$var], $_POST[$var], $_REQUEST[$var], $_COOKIE[$var]);
	}

	/**
	* @dataProvider deep_access
	* Only possible with 3.1.x (later)
	*/
	public function test_deep_multi_dim_array_access($path, $default, $expected)
	{
		$this->unset_variables('var');

		// cannot set $_REQUEST directly because in \phpbb\request\request implementation
		// $_REQUEST = $_POST + $_GET
		$_POST['var'] = array(
			0 => array(
				'b' => array(
					true => array(
						5 => 'c',
						6 => 'd',
					),
				),
			),
			2 => array(
				3 => array(
					false => 5,
				),
			),
		);

		$result = request_var($path, $default);
		$this->assertEquals($expected, $result, 'Testing deep access to multidimensional input arrays: ' . $path);
	}

	public function deep_access()
	{
		return array(
			// array(path, default, expected result)
			array(array('var', 0, 'b', true, 5), '', 'c'),
			array(array('var', 0, 'b', true, 6), '', 'd'),
			array(array('var', 2, 3, false), 0, 5),
			array(array('var', 0, 'b', true), array(0 => ''), array(5 => 'c', 6 => 'd')),
		);
	}

	public function request_variables()
	{
		return array(
			// strings
			array('abc', '', false, 'abc'),
			array('  some  spaces  ', '', true, 'some  spaces'),
			array("\r\rsome\rcarriage\r\rreturns\r", '', true, "some\ncarriage\n\nreturns"),
			array("\n\nsome\ncarriage\n\nreturns\n", '', true, "some\ncarriage\n\nreturns"),
			array("\r\n\r\nsome\r\ncarriage\r\n\r\nreturns\r\n", '', true, "some\ncarriage\n\nreturns"),
			array("we\xC2\xA1rd\xE1\x9A\x80ch\xCE\xB1r\xC2\xADacters", '', true, "we\xC2\xA1rd\xE1\x9A\x80ch\xCE\xB1r\xC2\xADacters"),
			array("we\xC2\xA1rd\xE1\x9A\x80ch\xCE\xB1r\xC2\xADacters", '', false, "we??rd???ch??r??acters"),
			array("Some <html> \"entities\" like &", '', true, "Some &lt;html&gt; &quot;entities&quot; like &amp;"),

			// integers
			array('1234', 0, false, 1234),
			array('abc', 12, false, 0),
			array('324abc', 0, false, 324),

			// string to array
			array('123', array(0), false, array()),
			array('123', array(''), false, array()),

			// 1 dimensional arrays
			array(
				// input:
				array('123', 'abc'),
				// default:
				array(''),
				false,
				// expected:
				array('123', 'abc')
			),
			array(
				// input:
				array('123', 'abc'),
				// default:
				array(999),
				false,
				// expected:
				array(123, 0)
			),
			array(
				// input:
				array('xyz' => '123', 'abc' => 'abc'),
				// default:
				array('' => ''),
				false,
				// expected:
				array('xyz' => '123', 'abc' => 'abc')
			),
			array(
				// input:
				array('xyz' => '123', 'abc' => 'abc'),
				// default:
				array('' => 0),
				false,
				// expected:
				array('xyz' => 123, 'abc' => 0)
			),

			// 2 dimensional arrays
			array(
				// input:
				'',
				// default:
				array(array(0)),
				false,
				// expected:
				array()
			),
			array(
				// input:
				array(
					'xyz' => array('123', 'def'),
					'abc' => 'abc'
				),
				// default:
				array('' => array('')),
				false,
				// expected:
				array(
					'xyz' => array('123', 'def'),
					'abc' => array()
				)
			),
			array(
				// input:
				array(
					'xyz' => array('123', 'def'),
					'abc' => 'abc'
				),
				// default:
				array('' => array(0)),
				false,
				// expected:
				array(
					'xyz' => array(123, 0),
					'abc' => array()
				)
			),
			array(
				// input:
				array(
					0 => array(0 => array(3, '4', 'ab'), 1 => array()),
					1 => array(array(3, 4)),
				),
				// default:
				array(0 => array(0 => array(0))),
				false,
				// expected:
				array(
					0 => array(0 => array(3, 4, 0), 1 => array()),
					1 => array(array(3, 4))
				)
			),
			array(
				// input:
				array(
					'ü' => array(array('c' => 'd')),
					'ä' => array(4 => array('a' => 2, 'ö' => 3)),
				),
				// default:
				array('' => array(0 => array('' => 0))),
				false,
				// expected:
				array(
					'??' => array(4 => array('a' => 2, '??' => 3)),
				)
			),
			array(
				// input:
				array(
					'ü' => array(array('c' => 'd')),
					'ä' => array(4 => array('a' => 2, 'ö' => 3)),
				),
				// default:
				array('' => array(0 => array('' => 0))),
				true,
				// expected:
				array(
					'ü' => array(array('c' => 0)),
					'ä' => array(4 => array('a' => 2, 'ö' => 3)),
				)
			),
		);
	}

}