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
This commit is contained in:
nate 2008-09-17 15:17:23 +00:00
parent 05a5eda3d1
commit 906dbcccbf
2 changed files with 29 additions and 0 deletions

View file

@ -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']);

View file

@ -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
*