Bladeren bron

Fixed path delimeters being stripped by chain routes affecting later routes

Ryan Mauger 10 jaren geleden
bovenliggende
commit
64d2ddf7fe
2 gewijzigde bestanden met toevoegingen van 67 en 1 verwijderingen
  1. 3 1
      library/Zend/Controller/Router/Route/Chain.php
  2. 64 0
      tests/Zend/Controller/Router/Route/ChainTest.php

+ 3 - 1
library/Zend/Controller/Router/Route/Chain.php

@@ -86,6 +86,7 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
      */
     public function match($request, $partial = null)
     {
+        $rawPath     = $request->getPathInfo();
         $path        = trim($request->getPathInfo(), self::URI_DELIMITER);
         $subPath     = $path;
         $values      = array();
@@ -100,6 +101,7 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
                 $separator = substr($subPath, 0, strlen($this->_separators[$key]));
 
                 if ($separator !== $this->_separators[$key]) {
+                    $request->setPathInfo($rawPath);
                     return false;
                 }
 
@@ -116,7 +118,7 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
             $res = $route->match($match, true);
 
             if ($res === false) {
-                $request->setPathInfo($path);
+                $request->setPathInfo($rawPath);
                 return false;
             }
 

+ 64 - 0
tests/Zend/Controller/Router/Route/ChainTest.php

@@ -840,6 +840,30 @@ class Zend_Controller_Router_Route_ChainTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * @throws Zend_Controller_Router_Exception
+     */
+    public function testMultipleChainsResettingPathInfoInSegmentBlock()
+    {
+        $foo = new Zend_Controller_Router_Route_SubclassTest('notfoo');
+        $bar = new Zend_Controller_Router_Route_SubclassTest('bar', array('baz' => 'no'));
+
+
+        $chain = $foo->chain($bar);
+
+        $static = new Zend_Controller_Router_Route_SimpleSubclassTest('/foo', array('foo' => 'foo'));
+
+        $rewrite = new Zend_Controller_Router_Rewrite();
+        $rewrite->addRoute('static', $static); // First In Last Out, we want this to be matched against second
+        $rewrite->addRoute('chain', $chain);
+        $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo');
+
+        $res = $rewrite->route($request);
+        $this->assertEquals('foo', $res->getParam('foo'), 'Route did not match');
+        $this->assertEquals('static', $rewrite->getCurrentRouteName(), 'Routing did not match expected route');
+
+    }
+
+    /**
      * @group ZF-11443
      */
     public function testGetDefault()
@@ -958,6 +982,46 @@ class Zend_Controller_Router_Route_ChainTest extends PHPUnit_Framework_TestCase
     }
 }
 
+class Zend_Controller_Router_Route_SimpleSubclassTest extends Zend_Controller_Router_Route_Abstract
+{
+    /**
+     * @var string
+     */
+    protected $path;
+
+    /**
+     * @var array
+     */
+    protected $params = array();
+
+    public function __construct($path, $params)
+    {
+        $this->path = $path;
+        $this->params = $params;
+    }
+
+    public function match($path, $partial = false)
+    {
+        $path = $path->getPathInfo();
+        if ($path == $this->path) {
+            $this->setMatchedPath($this->path);
+            return $this->params;
+        }
+        return false;
+    }
+
+    public function getVersion()
+    {
+        return 2;
+    }
+
+    public function assemble($data = array(), $reset = false, $encode = false)
+    {}
+
+    public static function getInstance(Zend_Config $config)
+    {}
+
+}
 
 class Zend_Controller_Router_Route_SubclassTest extends Zend_Controller_Router_Route_Static
 {