Fix detecting PATH_INFO if using URL rewriting.
authorJan Schneider <jan@horde.org>
Tue, 21 Dec 2010 19:06:43 +0000 (20:06 +0100)
committerJan Schneider <jan@horde.org>
Tue, 21 Dec 2010 19:14:56 +0000 (20:14 +0100)
framework/Util/lib/Horde/Util.php
framework/Util/test/Horde/Util/UtilTest.php

index 38c6b98..1094ea8 100644 (file)
@@ -720,16 +720,19 @@ class Horde_Util
             return $_SERVER['PATH_INFO'];
         } elseif (isset($_SERVER['REQUEST_URI']) &&
                   isset($_SERVER['SCRIPT_NAME'])) {
-            if (basename($_SERVER['SCRIPT_NAME']) == 'index.php') {
-                $search = array(dirname($_SERVER['SCRIPT_NAME']) . '/',
-                                'index.php');
-            } else {
-                $search = array($_SERVER['SCRIPT_NAME']);
+            $search = Horde_String::common($_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI']);
+            if (substr($search, -1) == '/') {
+                $search = substr($search, 0, -1);
             }
+            $search = array($search);
             if (!empty($_SERVER['QUERY_STRING'])) {
                 $search[] = '?' . $_SERVER['QUERY_STRING'];
             }
-            return str_replace($search, '', $_SERVER['REQUEST_URI']);
+            $path = str_replace($search, '', $_SERVER['REQUEST_URI']);
+            if ($path == '/') {
+                $path = '';
+            }
+            return $path;
         }
 
         return '';
index 84881e1..675b950 100644 (file)
@@ -1,12 +1,16 @@
 <?php
 /**
+ * Require our basic test case definition
+ */
+require_once dirname(__FILE__) . '/Autoload.php';
+
+/**
  * @author     Jan Schneider <jan@horde.org>
  * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
  * @category   Horde
  * @package    Util
  * @subpackage UnitTests
  */
-
 class Horde_Util_UtilTest extends PHPUnit_Framework_TestCase
 {
     public function testAddParameter()
@@ -112,6 +116,8 @@ class Horde_Util_UtilTest extends PHPUnit_Framework_TestCase
         $_SERVER['REQUEST_URI'] = '/horde/path.php/foo/bar?baz';
         $_SERVER['QUERY_STRING'] = 'baz';
         $this->assertEquals('/foo/bar', Horde_Util::getPathInfo());
+        $_SERVER['REQUEST_URI'] = '/horde/foo/bar?baz';
+        $this->assertEquals('/foo/bar', Horde_Util::getPathInfo());
 
         $_SERVER['REQUEST_URI'] = '/horde/';
         $_SERVER['SCRIPT_NAME'] = '/horde/index.php';