fixing bug with url parsing

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5468 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-07-27 02:46:30 +00:00
parent 9a915e90ef
commit fc9503e473
2 changed files with 20 additions and 3 deletions

View file

@ -210,7 +210,7 @@ class Router extends Object {
* Creates REST resource routes for the given controller(s) * Creates REST resource routes for the given controller(s)
* *
* @param mixed $controller A controller name or array of controller names (i.e. "Posts" or "ListItems") * @param mixed $controller A controller name or array of controller names (i.e. "Posts" or "ListItems")
* @param array $options * @param array $options
* @access public * @access public
* @static * @static
*/ */
@ -334,8 +334,8 @@ class Router extends Object {
} else { } else {
// unnamed elements go in as 'pass' // unnamed elements go in as 'pass'
$search = explode('/', $found); $search = explode('/', $found);
foreach ($search as $k => $value) { foreach (Set::filter($search, true) as $k => $value) {
$out['pass'][] = $_this->stripEscape($value); $out['pass'][$k] = $_this->stripEscape($value);
} }
} }
} }

View file

@ -336,6 +336,23 @@ class RouterTest extends UnitTestCase {
$expected = array('user' => 'gwoo', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array()); $expected = array('user' => 'gwoo', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array());
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
function testPagesUrlParsing() {
$this->router->routes = array();
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display', 'home'));
$result = $this->router->parse('/pages/home/');
$expected = array('pass'=>array('home'), 'plugin'=> null, 'controller'=>'pages', 'action'=>'display');
$this->assertEqual($result, $expected);
$this->router->routes = array();
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
$result = $this->router->parse('/pages/contact/');
$expected = array('pass'=>array('contact'), 'plugin'=> null, 'controller'=>'pages', 'action'=>'display');
$this->assertEqual($result, $expected);
}
} }
?> ?>