Restricted named route element to contain no special chars other then '_'

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6559 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-03-11 15:19:46 +00:00
parent 2c3ec768c7
commit 7a769f68ca
2 changed files with 8 additions and 6 deletions

View file

@ -313,7 +313,7 @@ class Router extends Object {
$names[] = $r[1];
} elseif ($element == '*') {
$parsed[] = '(?:/(.*))?';
} else if ($namedParam && preg_match_all('/(?!\\\\):([^:\\\\]+)/', $element, $matches)) {
} else if ($namedParam && preg_match_all('/(?!\\\\):([a-z_0-9]+)/i', $element, $matches)) {
foreach ($matches[1] as $i => $name) {
$pos = strpos($element, ':'.$name);
$before = substr($element, 0, $pos);

View file

@ -89,11 +89,13 @@ class RouterTest extends UnitTestCase {
$this->assertEqual($this->router->routes[0][2], array('id'));
$this->assertEqual($this->router->routes[0][1], '#^/posts(?:/foo([^\/]+))?[\/]*$#');
$this->router->routes = array();
$this->router->connect('/posts/:id::title');
$this->assertEqual($this->router->routes[0][2], array('id', 'title'));
$this->assertEqual($this->router->routes[0][1], '#^/posts(?:/([^\/]+))?(?:\\:([^\/]+))?[\/]*$#');
foreach (array(':', '@', ';', '$', '-') as $delim) {
$this->router->routes = array();
$this->router->connect('/posts/:id'.$delim.':title');
$this->assertEqual($this->router->routes[0][2], array('id', 'title'));
$this->assertEqual($this->router->routes[0][1], '#^/posts(?:/([^\/]+))?(?:'.preg_quote($delim, '#').'([^\/]+))?[\/]*$#');
}
$this->router->routes = array();
$this->router->connect('/posts/:id::title/:year');
$this->assertEqual($this->router->routes[0][2], array('id', 'title', 'year'));