Added support for final characters in multi param route elements

Fixed issue with reverse routing and falsely escaped route regex

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6647 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-04-09 18:26:20 +00:00
parent 5be760a055
commit 4b19d4c38d
2 changed files with 16 additions and 6 deletions

View file

@ -314,21 +314,24 @@ class Router extends Object {
$parsed[] = '(?:/(.*))?';
} else if ($namedParam && preg_match_all('/(?!\\\\):([a-z_0-9]+)/i', $element, $matches)) {
foreach ($matches[1] as $i => $name) {
$pos = strpos($element, ':'.$name);
$pos = strpos($element, ':' . $name);
$before = substr($element, 0, $pos);
$element = substr($element, $pos+strlen($name)+1);
$after = null;
if (next($matches[1]) === false && $element) {
$after = preg_quote($element);
}
if ($i == 0) {
$before = '/'.$before;
$before = '/' . $before;
}
$before = preg_quote($before, '#');
if (isset($params[$name])) {
if (array_key_exists($name, $default) && $name != 'plugin') {
$q = '?';
}
$parsed[] = '(?:'.$before.'(' . $params[$name] . ')' . $q . ')' . $q;
$parsed[] = '(?:' . $before . '(' . $params[$name] . ')' . $q . $after . ')' . $q;
} else {
$parsed[] = '(?:'.$before.'([^\/]+))?';
$parsed[] = '(?:' . $before . '([^\/]+)' . $after . ')?';
}
$names[] = $name;
}
@ -934,7 +937,7 @@ class Router extends Object {
if (!empty($route[4])) {
foreach ($route[4] as $key => $reg) {
if (array_key_exists($key, $url) && !preg_match('/' . $reg . '/', $url[$key])) {
if (array_key_exists($key, $url) && !preg_match('#' . $reg . '#', $url[$key])) {
return false;
}
}

View file

@ -649,6 +649,13 @@ class RouterTest extends UnitTestCase {
$result = $this->router->parse('/posts/5:sample-post-title/other/params/4');
$expected = array('pass' => array('5', 'sample-post-title', 'other', 'params', '4'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
$this->assertEqual($result, $expected);
$this->router->reload();
$this->router->connect('/posts/:url_title-(uuid::id)', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => $UUID));
$result = $this->router->parse('/posts/sample-post-title-(uuid:47fc97a9-019c-41d1-a058-1fa3cbdd56cb)');
$expected = array('pass' => array('47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'sample-post-title'), 'named' => array(), 'id' => '47fc97a9-019c-41d1-a058-1fa3cbdd56cb', 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
$this->assertEqual($result, $expected);
}
function testUuidRoutes() {