Parcourir la source

ZF-7917: Zend_Controller_Router_Route: ignore params which are equal to defaults

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18439 44c647ce-9c0f-0410-b52a-842ac1e357ba
jan il y a 16 ans
Parent
commit
fa6f59d1a4

+ 2 - 1
library/Zend/Controller/Router/Route.php

@@ -371,8 +371,9 @@ class Zend_Controller_Router_Route extends Zend_Controller_Router_Route_Abstract
                 }
             } else {
                 if (!$reset) $data += $this->_wildcardData;
+                $defaults = $this->getDefaults();
                 foreach ($data as $var => $value) {
-                    if ($value !== null) {
+                    if ($value !== null && (!isset($defaults[$var]) || $value != $defaults[$var])) {
                         $url[$key++] = $var;
                         $url[$key++] = $value;
                         $flag = true;

+ 18 - 0
tests/Zend/Controller/Router/RouteTest.php

@@ -441,6 +441,24 @@ class Zend_Controller_Router_RouteTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('archives/2006/03', $url);
     }
 
+    /**
+     * @group ZF-7917
+     */
+    public function testAssembleWithGivenDataEqualsDefaults()
+    {
+        $route = new Zend_Controller_Router_Route('index/*', array(
+            'module'     => 'default',
+            'controller' => 'index',
+            'action'     => 'index'
+        ));
+        
+        $this->assertEquals('index', $route->assemble(array(
+            'module'     => 'default',
+            'controller' => 'index',
+            'action'     => 'index'
+        )));
+    }
+
     public function testWildcardUrlVariablesOverwriting()
     {
         $route = new Zend_Controller_Router_Route('archives/:year/:month/*', array('controller' => 'archive'));