mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
2c3ec768c7
commit
7a769f68ca
2 changed files with 8 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in a new issue