Bladeren bron

ZF-3527, ZF-11017, ZF-10964, ZF-10787
Fixed Zend_Controller_Request_Http to respect encoding but remove possible baseurls


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24002 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 14 jaren geleden
bovenliggende
commit
0afbdfba07
2 gewijzigde bestanden met toevoegingen van 38 en 18 verwijderingen
  1. 24 18
      library/Zend/Controller/Request/Http.php
  2. 14 0
      tests/Zend/Controller/Request/HttpTest.php

+ 24 - 18
library/Zend/Controller/Request/Http.php

@@ -545,13 +545,13 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
      *
      * @return string
      */
-    public function getBaseUrl()
+    public function getBaseUrl($raw = false)
     {
         if (null === $this->_baseUrl) {
             $this->setBaseUrl();
         }
 
-        return urldecode($this->_baseUrl);
+        return (($raw == false) ? urldecode($this->_baseUrl) : $this->_baseUrl);
     }
 
     /**
@@ -612,31 +612,37 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
     public function setPathInfo($pathInfo = null)
     {
         if ($pathInfo === null) {
-            $baseUrl = $this->getBaseUrl();
-
+            $baseUrl = $this->getBaseUrl(); // this actually calls setBaseUrl() & setRequestUri()
+            $baseUrlRaw = $this->getBaseUrl(false);
+            $baseUrlEncoded = urlencode($baseUrlRaw);
+        
             if (null === ($requestUri = $this->getRequestUri())) {
                 return $this;
             }
-
+        
             // Remove the query string from REQUEST_URI
             if ($pos = strpos($requestUri, '?')) {
                 $requestUri = substr($requestUri, 0, $pos);
             }
-
-            $requestUri = urldecode($requestUri);
-
-            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
-                    || (!empty($baseUrl) && false === strpos($requestUri, $baseUrl))
-            ) {
+        
+            $requestUriDecoded = urldecode($requestUri);
+            
+            $pathInfo = '';
+            
+            if (!empty($baseUrl) || !empty($baseUrlRaw)) {
+                if (strpos($requestUri, $baseUrl) === 0) {
+                    $pathInfo = substr($requestUri, strlen($baseUrl));
+                } elseif (strpos($requestUri, $baseUrlRaw) === 0) {
+                    $pathInfo = substr($requestUri, strlen($baseUrlRaw));
+                } elseif (strpos($requestUri, $baseUrlEncoded) === 0) {
+                    $pathInfo = substr($requestUri, strlen($baseUrlEncoded));
+                } else {
+                    $pathInfo = $requestUri;
+                }
+            } else {
                 $pathInfo = $requestUri;
             }
+        
         }
 
         $this->_pathInfo = (string) $pathInfo;

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

@@ -948,6 +948,20 @@ class Zend_Controller_Request_HttpTest extends PHPUnit_Framework_TestCase
 
         $this->assertEquals( '/module/controller/action', $pathInfo, $pathInfo);
     }
+    
+    /**
+     * @group ZF-3527
+     * @group ZF-10964
+     * @group ZF-10787
+     */
+    public function testPathInfoShouldNotDecodeRequestParams()
+    {
+        $request = new Zend_Controller_Request_Http();
+        $_SERVER['REQUEST_URI'] = '/module/controller/action/param/escaped%2Fstring';
+        $pathInfo = $request->getPathInfo();
+    
+        $this->assertEquals( '/module/controller/action/param/escaped%2Fstring', $pathInfo, $pathInfo);
+    }
 
     /**
      * @group ZF-9899