From 17e4e5f8c4995f5818411382ccf4b799ddbe0b11 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 4 Sep 2014 13:33:04 +0200 Subject: [PATCH 1/4] [ticket/12852] Make get_url_parts handle get variable with no value PHPBB3-12852 --- phpBB/phpbb/path_helper.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index 38dbbab51e..b2758f8654 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -316,7 +316,7 @@ class path_helper * Glue URL parameters together * * @param array $params URL parameters in the form of array(name => value) - * @return string Returns the glued string, e.g. name1=value1&name2=value2 + * @return string Returns the glued string, e.g. name1=value1&name2&name3=value3 */ public function glue_url_params($params) { @@ -324,7 +324,15 @@ class path_helper foreach ($params as $key => $value) { - $_params[] = $key . '=' . $value; + // some parameters do not have value + if($value !== null) + { + $_params[] = $key . '=' . $value; + } + else + { + $_params[] = $key; + } } return implode('&', $_params); } @@ -353,7 +361,17 @@ class path_helper { continue; } - list($key, $value) = explode('=', $argument, 2); + + // some parameters don't have value + if (strpos($argument, '=') !== false) + { + list($key, $value) = explode('=', $argument, 2); + } + else + { + $key = $argument; + $value = null; + } if ($key === '') { From 28587d0afcdcf62b773f96bf5f78e57432a9d40e Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 4 Sep 2014 16:15:45 +0200 Subject: [PATCH 2/4] [ticket/12852] Remove whitespace PHPBB3-12852 --- phpBB/phpbb/path_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index b2758f8654..4b0f09024a 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -361,7 +361,7 @@ class path_helper { continue; } - + // some parameters don't have value if (strpos($argument, '=') !== false) { From 1d4cae9ecb08bcb55919a28895f68026b0539e4a Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 4 Sep 2014 17:44:41 +0200 Subject: [PATCH 3/4] [ticket/12852] Add space after if PHPBB3-12852 --- phpBB/phpbb/path_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index 4b0f09024a..936564d8b6 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -325,7 +325,7 @@ class path_helper foreach ($params as $key => $value) { // some parameters do not have value - if($value !== null) + if ($value !== null) { $_params[] = $key . '=' . $value; } From 7b796532dfbdccbca9ad66e1e752950e0c9e84b0 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 4 Sep 2014 17:56:48 +0200 Subject: [PATCH 4/4] [ticket/12852] Add unit tests PHPBB3-12852 --- tests/path_helper/path_helper_test.php | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 27e94d6a07..3832307897 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -205,6 +205,18 @@ class phpbb_path_helper_test extends phpbb_test_case array('test' => 'xyz', 'var' => 'value'), 'test=xyz&var=value', ), + array( + array('test' => null), + 'test', + ), + array( + array('test' => null, 'var' => null), + 'test&var', + ), + array( + array('test' => 'xyz', 'var' => null, 'bar' => 'value'), + 'test=xyz&var&bar=value', + ), ); } @@ -254,6 +266,21 @@ class phpbb_path_helper_test extends phpbb_test_case true, array('base' => 'mcp.php', 'params' => array('f' => '3')), ), + array( + 'index.php?ready', + false, + array('base' => 'index.php', 'params' => array('ready' => null)), + ), + array( + 'index.php?i=1&ready', + true, + array('base' => 'index.php', 'params' => array('i' => '1', 'ready' => null)), + ), + array( + 'index.php?ready&i=1', + false, + array('base' => 'index.php', 'params' => array('ready' => null, 'i' => '1')), + ), ); }