diff --git a/cake/libs/router.php b/cake/libs/router.php index 21b456f23..681d9eb34 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -786,12 +786,27 @@ class Router extends Object { if (!strpos($route[0], '*') && (!empty($pass) || !empty($named))) { return false; } + + $urlKeys = array_keys($url); + $paramsKeys = array_keys($params); + $defaultsKeys = array_keys($defaults); + if (!empty($params)) { - if (array_diff(array_keys($params), $routeParams) != array()) { + if (array_diff($paramsKeys, $routeParams) != array()) { return false; } - $required = array_diff(array_keys($defaults), array_keys($url)); + $required = array_diff($defaultsKeys, $urlKeys); } + + $isFilled = true; + if (!empty($routeParams)) { + $filled = array_intersect_key($url, array_combine($routeParams, array_keys($routeParams))); + $isFilled = (array_diff($routeParams, array_keys($filled)) == array()); + if (!$isFilled && empty($params)) { + return false; + } + } + if (empty($params)) { return Router::__mapRoute($route, am($url, compact('pass', 'named', 'prefix'))); } elseif (!empty($routeParams) && !empty($route[3])) { @@ -803,11 +818,6 @@ class Router extends Object { return false; } } - $filled = array_intersect_key($url, array_combine($routeParams, array_keys($routeParams))); - - if (array_diff(array_keys($filled), $routeParams) != array()) { - return false; - } } else { if (empty($required) && $defaults['plugin'] == $url['plugin'] && $defaults['controller'] == $url['controller'] && $defaults['action'] == $url['action']) { return Router::__mapRoute($route, am($url, compact('pass', 'named', 'prefix'))); diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 2e8b89511..068bfc34e 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -326,6 +326,27 @@ class RouterTest extends UnitTestCase { $result = $this->router->url(array('admin' => true, 'controller' => 'users', 'action' => 'login')); $expected = '/admin/users/login'; $this->assertEqual($result, $expected); + + $this->router->reload(); + $this->router->parse('/'); + + $this->router->connect('/kalender/:month/:year/*', + array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'), + array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}') + ); + + $this->router->connect('/kalender/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar')); + + $this->router->testing = true; + $result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling')); + unset($this->router->testing); + $expected = '/kalender/min-forestilling'; + $this->assertEqual($result, $expected); + + $result = $this->router->url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling')); + $expected = '/kalender/10/2007/min-forestilling'; + $this->assertEqual($result, $expected); + }