aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-08-18 23:19:48 +0200
committerIgor Wiedler <igor@wiedler.ch>2011-08-18 23:19:48 +0200
commitfd08cd8dd013c0d1bf8e18611f798c6987d9de9c (patch)
tree084176a8e8dabb15172d3b08476eba737984b8d4
parentb4ae124084a65b027af105e06077b5cf9e7c3023 (diff)
downloadforums-fd08cd8dd013c0d1bf8e18611f798c6987d9de9c.tar
forums-fd08cd8dd013c0d1bf8e18611f798c6987d9de9c.tar.gz
forums-fd08cd8dd013c0d1bf8e18611f798c6987d9de9c.tar.bz2
forums-fd08cd8dd013c0d1bf8e18611f798c6987d9de9c.tar.xz
forums-fd08cd8dd013c0d1bf8e18611f798c6987d9de9c.zip
[feature/request-class] Remove $html_encode arg, force manual decoding
PHPBB3-9716
-rw-r--r--phpBB/includes/request/interface.php9
-rw-r--r--phpBB/includes/request/request.php17
-rw-r--r--phpBB/includes/request/type_cast_helper.php18
-rw-r--r--tests/mock/request.php8
-rw-r--r--tests/request/request_test.php4
-rw-r--r--tests/request/type_cast_helper_test.php10
6 files changed, 21 insertions, 45 deletions
diff --git a/phpBB/includes/request/interface.php b/phpBB/includes/request/interface.php
index c0b8768b24..181bcb467a 100644
--- a/phpBB/includes/request/interface.php
+++ b/phpBB/includes/request/interface.php
@@ -61,34 +61,31 @@ interface phpbb_request_interface
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global
* Specifies which super global should be used
- * @param bool $html_encode When true, html encoding will be applied
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
- public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true);
+ public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST);
/**
* Shortcut method to retrieve SERVER variables.
*
* @param string|array $var_name See phpbb_request_interface::variable
* @param mixed $default See phpbb_request_interface::variable
- * @param bool $html_encode See phpbb_request_interface::variable
*
* @return mixed The server variable value.
*/
- public function server($var_name, $default = '', $html_encode = false);
+ public function server($var_name, $default = '');
/**
* Shortcut method to retrieve the value of client HTTP headers.
*
* @param string|array $header_name The name of the header to retrieve.
* @param mixed $default See phpbb_request_interface::variable
- * @param bool $html_encode See phpbb_request_interface::variable
*
* @return mixed The header value.
*/
- public function header($var_name, $default = '', $html_encode = false);
+ public function header($var_name, $default = '');
/**
* Checks whether a certain variable was sent via POST.
diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php
index 8659ee8998..9386088a07 100644
--- a/phpBB/includes/request/request.php
+++ b/phpBB/includes/request/request.php
@@ -194,12 +194,11 @@ class phpbb_request implements phpbb_request_interface
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global
* Specifies which super global should be used
- * @param bool $html_encode When true, html encoding will be applied
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
- public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true)
+ public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST)
{
$path = false;
@@ -238,7 +237,7 @@ class phpbb_request implements phpbb_request_interface
}
}
- $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $html_encode);
+ $this->type_cast_helper->recursive_set_var($var, $default, $multibyte);
return $var;
}
@@ -251,22 +250,21 @@ class phpbb_request implements phpbb_request_interface
*
* @param string|array $var_name See phpbb_request_interface::variable
* @param mixed $Default See phpbb_request_interface::variable
- * @param bool $html_encode See phpbb_request_interface::variable
*
* @return mixed The server variable value.
*/
- public function server($var_name, $default = '', $html_encode = false)
+ public function server($var_name, $default = '')
{
$multibyte = true;
if ($this->is_set($var_name, phpbb_request_interface::SERVER))
{
- return $this->variable($var_name, $default, $multibyte, phpbb_request_interface::SERVER, $html_encode);
+ return $this->variable($var_name, $default, $multibyte, phpbb_request_interface::SERVER);
}
else
{
$var = getenv($var_name);
- $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $html_encode);
+ $this->type_cast_helper->recursive_set_var($var, $default, $multibyte);
return $var;
}
}
@@ -276,14 +274,13 @@ class phpbb_request implements phpbb_request_interface
*
* @param string|array $header_name The name of the header to retrieve.
* @param mixed $default See phpbb_request_interface::variable
- * @param bool $html_encode See phpbb_request_interface::variable
*
* @return mixed The header value.
*/
- public function header($header_name, $default = '', $html_encode = true)
+ public function header($header_name, $default = '')
{
$var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
- return $this->server($var_name, $default, $html_encode);
+ return $this->server($var_name, $default);
}
/**
diff --git a/phpBB/includes/request/type_cast_helper.php b/phpBB/includes/request/type_cast_helper.php
index f84d71fa1c..96ceb0df1d 100644
--- a/phpBB/includes/request/type_cast_helper.php
+++ b/phpBB/includes/request/type_cast_helper.php
@@ -93,9 +93,8 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i
* @param mixed $type The variable type. Will be used with {@link settype()}
* @param bool $multibyte Indicates whether string values may contain UTF-8 characters.
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks.
- * @param bool $html_encode When true, html encoding will be applied
*/
- public function set_var(&$result, $var, $type, $multibyte = false, $html_encode = true)
+ public function set_var(&$result, $var, $type, $multibyte = false)
{
settype($var, $type);
$result = $var;
@@ -103,11 +102,7 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i
if ($type == 'string')
{
$result = trim(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $result));
-
- if ($html_encode)
- {
- $result = htmlspecialchars($result, ENT_COMPAT, 'UTF-8');
- }
+ $result = htmlspecialchars($result, ENT_COMPAT, 'UTF-8');
if ($multibyte)
{
@@ -146,9 +141,8 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i
* @param bool $multibyte Indicates whether string keys and values may contain UTF-8 characters.
* Default is false, causing all bytes outside the ASCII range (0-127) to
* be replaced with question marks.
- * @param bool $html_encode When true, html encoding will be applied
*/
- public function recursive_set_var(&$var, $default, $multibyte, $html_encode = true)
+ public function recursive_set_var(&$var, $default, $multibyte)
{
if (is_array($var) !== is_array($default))
{
@@ -159,7 +153,7 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i
if (!is_array($default))
{
$type = gettype($default);
- $this->set_var($var, $var, $type, $multibyte, $html_encode);
+ $this->set_var($var, $var, $type, $multibyte);
}
else
{
@@ -180,9 +174,9 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i
foreach ($_var as $k => $v)
{
- $this->set_var($k, $k, $key_type, $multibyte, $multibyte, $html_encode);
+ $this->set_var($k, $k, $key_type, $multibyte, $multibyte);
- $this->recursive_set_var($v, $default_value, $multibyte, $html_encode);
+ $this->recursive_set_var($v, $default_value, $multibyte);
$var[$k] = $v;
}
}
diff --git a/tests/mock/request.php b/tests/mock/request.php
index 18aa2e724c..8b2708304c 100644
--- a/tests/mock/request.php
+++ b/tests/mock/request.php
@@ -25,21 +25,21 @@ class phpbb_mock_request implements phpbb_request_interface
$this->data[$super_global][$var_name] = $value;
}
- public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true)
+ public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST)
{
return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default;
}
- public function server($var_name, $default = '', $html_encode = false)
+ public function server($var_name, $default = '')
{
$super_global = phpbb_request_interface::SERVER;
return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default;
}
- public function header($header_name, $default = '', $html_encode = false)
+ public function header($header_name, $default = '')
{
$var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
- return $this->server($var_name, $default, $html_encode);
+ return $this->server($var_name, $default);
}
public function is_set_post($name)
diff --git a/tests/request/request_test.php b/tests/request/request_test.php
index 2e56841601..e492fa5cf1 100644
--- a/tests/request/request_test.php
+++ b/tests/request/request_test.php
@@ -60,8 +60,7 @@ class phpbb_request_test extends phpbb_test_case
->with(
$this->anything(),
'',
- true,
- false
+ true
);
$this->request->server('HTTP_SOMEVAR');
@@ -80,7 +79,6 @@ class phpbb_request_test extends phpbb_test_case
->with(
$this->anything(),
'',
- true,
true
);
diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php
index 0103c51561..06cf2e1bf6 100644
--- a/tests/request/type_cast_helper_test.php
+++ b/tests/request/type_cast_helper_test.php
@@ -48,14 +48,4 @@ class phpbb_type_cast_helper_test extends phpbb_test_case
$this->assertEquals($expected, $data);
}
-
- public function test_simple_set_var_without_html_encoding()
- {
- $data = 'eviL<3';
- $expected = 'eviL<3';
-
- $this->type_cast_helper->recursive_set_var($data, '', true, false);
-
- $this->assertEquals($expected, $data);
- }
}