From efa8ab0b6b29210a3e9c2f427ecb4c90d7f4b1b6 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 21 Dec 2010 22:18:13 +0100 Subject: [PATCH] Catch more edge cases with rewrite URLs. --- framework/Core/test/Horde/Core/UrlTest.php | 6 ++++++ framework/Util/lib/Horde/Util.php | 8 +++++++- framework/Util/test/Horde/Util/UtilTest.php | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/framework/Core/test/Horde/Core/UrlTest.php b/framework/Core/test/Horde/Core/UrlTest.php index 543d1c9b6..296fc91a4 100644 --- a/framework/Core/test/Horde/Core/UrlTest.php +++ b/framework/Core/test/Horde/Core/UrlTest.php @@ -354,6 +354,12 @@ class Horde_Core_UrlTest extends PHPUnit_Framework_TestCase $_SERVER['SCRIPT_NAME'] = '/hordeurl/test.php'; $this->assertEquals('/hordeurl/', (string)Horde::selfUrl()); $this->assertEquals('/hordeurl/foo/bar?foo=bar&x=y', (string)Horde::selfUrl(true)); + + // Special cases. + $_SERVER['REQUEST_URI'] = '/test/42?id=42'; + $_SERVER['SCRIPT_NAME'] = '/test/index.php'; + $_SERVER['QUERY_STRING'] = 'id=42&id=42'; + $this->assertEquals('/test/42?id=42', (string)Horde::selfUrl(true)); } } diff --git a/framework/Util/lib/Horde/Util.php b/framework/Util/lib/Horde/Util.php index 1094ea8c8..a0e825d47 100644 --- a/framework/Util/lib/Horde/Util.php +++ b/framework/Util/lib/Horde/Util.php @@ -726,7 +726,13 @@ class Horde_Util } $search = array($search); if (!empty($_SERVER['QUERY_STRING'])) { - $search[] = '?' . $_SERVER['QUERY_STRING']; + // We can't use QUERY_STRING directly because URL rewriting + // might add more parameters to the query string than those + // from the request URI. + $url = parse_url($_SERVER['REQUEST_URI']); + if (!empty($url['query'])) { + $search[] = '?' . $url['query']; + } } $path = str_replace($search, '', $_SERVER['REQUEST_URI']); if ($path == '/') { diff --git a/framework/Util/test/Horde/Util/UtilTest.php b/framework/Util/test/Horde/Util/UtilTest.php index 675b950c4..75c70b436 100644 --- a/framework/Util/test/Horde/Util/UtilTest.php +++ b/framework/Util/test/Horde/Util/UtilTest.php @@ -138,5 +138,10 @@ class Horde_Util_UtilTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_URI'] = '/horde/index.php/foo/bar?baz'; $_SERVER['QUERY_STRING'] = 'baz'; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); + + $_SERVER['REQUEST_URI'] = '/test/42?id=42'; + $_SERVER['SCRIPT_NAME'] = '/test/index.php'; + $_SERVER['QUERY_STRING'] = 'id=42&id=42'; + $this->assertEquals('/42', Horde_Util::getPathInfo()); } } -- 2.11.0