From fc9503e473470199b19ca248920046d2368ee909 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 27 Jul 2007 02:46:30 +0000 Subject: [PATCH] fixing bug with url parsing git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5468 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 6 +++--- cake/tests/cases/libs/router.test.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index ce36f97fe..cd91efd69 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -210,7 +210,7 @@ class Router extends Object { * 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 array $options + * @param array $options * @access public * @static */ @@ -334,8 +334,8 @@ class Router extends Object { } else { // unnamed elements go in as 'pass' $search = explode('/', $found); - foreach ($search as $k => $value) { - $out['pass'][] = $_this->stripEscape($value); + foreach (Set::filter($search, true) as $k => $value) { + $out['pass'][$k] = $_this->stripEscape($value); } } } diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index d23326a68..a01e88d06 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -336,6 +336,23 @@ class RouterTest extends UnitTestCase { $expected = array('user' => 'gwoo', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array()); $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); + } } ?> \ No newline at end of file