2
0
Просмотр исходного кода

ZF-9091: check for baseUrl in requestUri prior to removing it

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20983 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 лет назад
Родитель
Сommit
185fcd838b
2 измененных файлов с 22 добавлено и 6 удалено
  1. 10 6
      library/Zend/Controller/Request/Http.php
  2. 12 0
      tests/Zend/Controller/Request/HttpTest.php

+ 10 - 6
library/Zend/Controller/Request/Http.php

@@ -623,13 +623,17 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
                 $requestUri = substr($requestUri, 0, $pos);
             }
 
-            if ((null !== $baseUrl)
-                && (false === ($pathInfo = substr($requestUri, strlen($baseUrl)))))
-            {
-                // If substr() returns false then PATH_INFO is set to an empty string
+            if (null !== $baseUrl
+                && ((!empty($baseUrl) && 0 === strpos($requestUri, $baseUrl)) 
+                    || empty($baseUrl))
+                    && false === ($pathInfo = substr($requestUri, strlen($baseUrl)))
+            ){ 
+                // If substr() returns false then PATH_INFO is set to an empty string 
                 $pathInfo = '';
-            } elseif (null === $baseUrl) {
-                $pathInfo = $requestUri;
+            } elseif (null === $baseUrl 
+                    || (!empty($baseUrl) && false === strpos($requestUri, $baseUrl))
+            ) { 
+                $pathInfo = $requestUri; 
             }
         }
 

+ 12 - 0
tests/Zend/Controller/Request/HttpTest.php

@@ -827,6 +827,18 @@ class Zend_Controller_Request_HttpTest extends PHPUnit_Framework_TestCase
         $params = $this->_request->getParams();
         $this->assertEquals(array('foo' => 'baz'), $params);
     }
+
+    /**
+     * @group ZF-9091
+     */
+    public function testSetPathInfoShouldNotStripBaseUrlIfBaseUrlNotInRequestUri()
+    {
+        $request = new Zend_Controller_Request_Http();
+        $request->setBaseUrl('/app');
+        $_SERVER['REQUEST_URI'] = '/index/index';
+        $pathInfo = $request->getPathInfo();
+        $this->assertEquals('/index/index', $pathInfo);
+    }
 }
 
 // Call Zend_Controller_Request_HttpTest::main() if this source file is executed directly.