From dc149a43e49c1c2160549e25792c5ee650861e02 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 21 Aug 2011 13:14:15 +0200 Subject: [PATCH] [ticket/10321] Do not append the ? if the param-list is empty anyway. PHPBB3-10321 --- phpBB/includes/functions.php | 6 ++++ tests/session/append_sid_test.php | 51 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/session/append_sid_test.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6b6679bde5..c6258588ca 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2225,6 +2225,12 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; + if ($params === '' || (is_array($params) && empty($params))) + { + // Do not append the ? if the param-list is empty anyway. + $params = false; + } + // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately. // They could mimic most of what is within this function if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id)) diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php new file mode 100644 index 0000000000..4a95b2d20e --- /dev/null +++ b/tests/session/append_sid_test.php @@ -0,0 +1,51 @@ + 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2'), + + // Custom sid parameter + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid'), + + // Testing anchors + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor'), + + // Anchors and custom sid + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + + // Empty parameters should not append the ? + array('viewtopic.php', false, true, false, 'viewtopic.php'), + array('viewtopic.php', '', true, false, 'viewtopic.php'), + array('viewtopic.php', array(), true, false, 'viewtopic.php'), + ); + } + + /** + * @dataProvider append_sid_data + */ + public function test_append_sid($url, $params, $is_amp, $session_id, $expected) + { + $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); + } +} +