Skip to content

Commit

Permalink
Removing optional group flag for routed parameters. Fixes issues with…
Browse files Browse the repository at this point in the history
… trailing empty route parameters. Tests added for correct parsing of these routes. Fixes #252
  • Loading branch information
markstory committed Jan 25, 2010
1 parent f6d12db commit 38eac37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cake/libs/router.php
Expand Up @@ -1307,7 +1307,7 @@ function _writeRoute() {
$replacements[] = '(?:(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
}
} else {
$replacements[] = '(?:(?P<' . $name . '>[^/]+))?';
$replacements[] = '(?:(?P<' . $name . '>[^/]+))';
$search[] = '\\' . $namedElements[0][$i];
}
$names[] = $name;
Expand All @@ -1334,7 +1334,6 @@ function parse($url) {
if (!$this->compiled()) {
$this->compile();
}

if (!preg_match($this->_compiledRoute, $url, $route)) {
return false;
} else {
Expand Down
14 changes: 13 additions & 1 deletion cake/tests/cases/libs/router.test.php
Expand Up @@ -2388,12 +2388,24 @@ function testPersistParams() {
*/
function testParse() {
extract(Router::getNamedExpressions());
$route = new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $ID));
$route =& new CakeRoute('/:controller/:action/:id', array('controller' => 'testing4', 'id' => null), array('id' => $ID));
$route->compile();
$result = $route->parse('/posts/view/1');
$this->assertEqual($result['controller'], 'posts');
$this->assertEqual($result['action'], 'view');
$this->assertEqual($result['id'], '1');

$route =& new Cakeroute(
'/admin/:controller',
array('prefix' => 'admin', 'admin' => 1, 'action' => 'index')
);
$route->compile();
$result = $route->parse('/admin/');
$this->assertFalse($result);

$result = $route->parse('/admin/posts');
$this->assertEqual($result['controller'], 'posts');
$this->assertEqual($result['action'], 'index');
}
}

Expand Down

0 comments on commit 38eac37

Please sign in to comment.