From 906dbcccbf160a00d7f6ffcacd16d6b0b005e79a Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 17 Sep 2008 15:17:23 +0000 Subject: [PATCH] Ensuring Dispatcher does not return an empty action, fixes #5434 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7615 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/dispatcher.php | 4 ++++ cake/tests/cases/dispatcher.test.php | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 45739d857..35b61a30b 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -318,6 +318,10 @@ class Dispatcher extends Object { include CONFIGS . 'routes.php'; $params = array_merge(Router::parse($fromUrl), $params); + if (empty($params['action'])) { + $params['action'] = 'index'; + } + if (isset($params['form']['data'])) { $params['data'] = Router::stripEscape($params['form']['data']); unset($params['form']['data']); diff --git a/cake/tests/cases/dispatcher.test.php b/cake/tests/cases/dispatcher.test.php index e2fe60c02..32f09c50d 100644 --- a/cake/tests/cases/dispatcher.test.php +++ b/cake/tests/cases/dispatcher.test.php @@ -1799,6 +1799,31 @@ class DispatcherTest extends CakeTestCase { } $this->__loadEnvironment(array_merge(array('reload' => true), $backup)); } +/** + * Tests that the Dispatcher does not return an empty action + * + * @access private + * @return void + */ + function testTrailingSlash() { + $_POST = array(); + $_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php'; + + Router::reload(); + $Dispatcher =& new TestDispatcher(); + Router::connect('/myalias/:action/*', array('controller' => 'my_controller', 'action' => null)); + + $Dispatcher->base = false; + $url = 'myalias/'; //Fails + $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $result = $Dispatcher->parseParams($url); + $this->assertEqual('index', $result['action']); + + $url = 'myalias'; //Passes + $controller = $Dispatcher->dispatch($url, array('return' => 1)); + $result = $Dispatcher->parseParams($url); + $this->assertEqual('index', $result['action']); + } /** * backupEnvironment method *