Catch more edge cases with rewrite URLs.
authorJan Schneider <jan@horde.org>
Tue, 21 Dec 2010 21:18:13 +0000 (22:18 +0100)
committerJan Schneider <jan@horde.org>
Tue, 21 Dec 2010 21:18:32 +0000 (22:18 +0100)
framework/Core/test/Horde/Core/UrlTest.php
framework/Util/lib/Horde/Util.php
framework/Util/test/Horde/Util/UtilTest.php

index 543d1c9..296fc91 100644 (file)
@@ -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&amp;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));
     }
 }
 
index 1094ea8..a0e825d 100644 (file)
@@ -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 == '/') {
index 675b950..75c70b4 100644 (file)
@@ -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());
     }
 }