diff --git a/cake/libs/router.php b/cake/libs/router.php index ce07b43e5..38af5334a 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -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; } } diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index f55780c19..cff65694e 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -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() {