Skip to content
Permalink
Browse files

Removing optional group flag for routed parameters. Fixes issues with…

… 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 38eac37bb1c3855765a2b642311d4c2ce3449c42
Showing with 14 additions and 3 deletions.
  1. +1 −2 cake/libs/router.php
  2. +13 −1 cake/tests/cases/libs/router.test.php
@@ -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;
@@ -1334,7 +1334,6 @@ function parse($url) {
if (!$this->compiled()) {
$this->compile();
}
if (!preg_match($this->_compiledRoute, $url, $route)) {
return false;
} else {
@@ -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');
}
}

0 comments on commit 38eac37

Please sign in to comment.
You can’t perform that action at this time.