Skip to content

Commit

Permalink
Removing defaults that are also keys this makes the actions with the …
Browse files Browse the repository at this point in the history
…default index key work much better. Also things can't be both a variable and a constant routing parameter.
  • Loading branch information
markstory committed Dec 1, 2009
1 parent 3930388 commit a8f79f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cake/libs/router.php
Expand Up @@ -1375,6 +1375,11 @@ function match($url) {
return false;
}

$count = count($this->keys);
while ($count--) {
unset($defaults[$this->keys[$count]]);
}

//if the difference between the url and defaults contains keys from defaults its not a match
if (array_intersect_key(array_filter($defaults), $diff) !== array()) {
return false;
Expand Down
17 changes: 8 additions & 9 deletions cake/tests/cases/libs/router.test.php
Expand Up @@ -379,9 +379,9 @@ function testUrlGenerationBasic() {
$this->assertEqual($result, $expected);

Router::reload();
Router::connect('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID));
Router::parse('/');

Router::connect('/:plugin/:id/*', array('controller' => 'posts', 'action' => 'view'), array('id' => $ID));
$result = Router::url(array('plugin' => 'cake_plugin', 'controller' => 'posts', 'action' => 'view', 'id' => '1'));
$expected = '/cake_plugin/1';
$this->assertEqual($result, $expected);
Expand All @@ -391,17 +391,17 @@ function testUrlGenerationBasic() {
$this->assertEqual($result, $expected);

Router::reload();
Router::parse('/');

Router::connect('/:controller/:action/:id', array(), array('id' => $ID));
Router::parse('/');

$result = Router::url(array('controller' => 'posts', 'action' => 'view', 'id' => '1'));
$expected = '/posts/view/1';
$this->assertEqual($result, $expected);

Router::reload();
Router::connect('/:controller/:id', array('action' => 'view'));
Router::parse('/');

Router::connect('/:controller/:id', array('action' => 'view'));
$result = Router::url(array('controller' => 'posts', 'action' => 'view', 'id' => '1'));
$expected = '/posts/1';
$this->assertEqual($result, $expected);
Expand Down Expand Up @@ -450,17 +450,17 @@ function testUrlGenerationBasic() {
$this->assertEqual($result, $expected);

Router::reload();
Router::parse('/');
Router::connect('/page/*', array('plugin' => null, 'controller' => 'pages', 'action' => 'view'));
Router::parse('/');

$result = Router::url(array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'view', 'my-page'));
$expected = '/my_plugin/pages/view/my-page';
$this->assertEqual($result, $expected);

Router::reload();
Router::connect('/contact/:action', array('plugin' => 'contact', 'controller' => 'contact'));
Router::parse('/');

Router::connect('/contact/:action', array('plugin' => 'contact', 'controller' => 'contact'));
$result = Router::url(array('plugin' => 'contact', 'controller' => 'contact', 'action' => 'me'));

$expected = '/contact/me';
Expand Down Expand Up @@ -543,7 +543,6 @@ function testUrlGenerationWithRegexQualifiedParams() {
array('controller' => 'pages', 'action' => 'index'),
array('language' => '[a-z]{3}')
);

Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}'));

$result = Router::url(array('language' => 'eng', 'action' => 'index', 'controller' => 'pages'));
Expand All @@ -558,23 +557,23 @@ function testUrlGenerationWithRegexQualifiedParams() {
$this->assertEqual($result, $expected);

Router::reload();
Router::parse('/');
Router::connect('/forestillinger/:month/:year/*',
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}')
);
Router::parse('/');

$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'month' => 10, 'year' => 2007, 'min-forestilling'));
$expected = '/forestillinger/10/2007/min-forestilling';
$this->assertEqual($result, $expected);

Router::reload();
Router::parse('/');
Router::connect('/kalender/:month/:year/*',
array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'),
array('month' => '0[1-9]|1[012]', 'year' => '[12][0-9]{3}')
);
Router::connect('/kalender/*', array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar'));
Router::parse('/');

$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'min-forestilling'));
$expected = '/kalender/min-forestilling';
Expand Down

0 comments on commit a8f79f9

Please sign in to comment.