mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding fixes for parameter matching in reverse routing (Ticket #3099)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5557 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8f8e471b5b
commit
c4c3bf4ccd
2 changed files with 38 additions and 7 deletions
|
@ -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')));
|
||||
|
|
|
@ -327,6 +327,27 @@ class RouterTest extends UnitTestCase {
|
|||
$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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testUrlGenerationWithExtensions() {
|
||||
|
|
Loading…
Add table
Reference in a new issue