Skip to content

Commit

Permalink
Moving action modification when a prefix is detected so it affects al…
Browse files Browse the repository at this point in the history
…l url arrays. Previously it was only applied to parameters in the current request. This fixes inconsistencies between request parameters and url parameters. Fixes #570
  • Loading branch information
markstory committed Apr 12, 2010
1 parent 42bc252 commit 404401b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cake/libs/router.php
Expand Up @@ -770,9 +770,6 @@ function url($url = null, $full = false) {
} else {
$params = end($self->__params);
}
if (isset($params['prefix']) && strpos($params['action'], $params['prefix']) === 0) {
$params['action'] = substr($params['action'], strlen($params['prefix']) + 1);
}
}
$path = array('base' => null);

Expand Down Expand Up @@ -818,6 +815,9 @@ function url($url = null, $full = false) {
} elseif (isset($url[$prefix]) && !$url[$prefix]) {
unset($url[$prefix]);
}
if (isset($url[$prefix]) && strpos($url['action'], $prefix) === 0) {
$url['action'] = substr($url['action'], strlen($prefix) + 1);
}
}

$url += array('controller' => $params['controller'], 'plugin' => $params['plugin']);
Expand Down
28 changes: 27 additions & 1 deletion cake/tests/cases/libs/router.test.php
Expand Up @@ -1741,14 +1741,40 @@ function testUrlWritingWithPrefixes() {

Router::setRequestInfo(array(
array('controller' => 'users', 'action' => 'login', 'company' => true, 'form' => array(), 'url' => array(), 'plugin' => null),
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
array('base' => '/', 'here' => '/', 'webroot' => '/base/')
));

$result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => false));
$expected = '/login';
$this->assertEqual($result, $expected);
}

/**
* test url generation with prefixes and custom routes
*
* @return void
*/
function testUrlWritingWithPrefixesAndCustomRoutes() {
Router::connect(
'/admin/login',
array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true)
);
Router::setRequestInfo(array(
array('controller' => 'posts', 'action' => 'index', 'admin' => true, 'prefix' => 'admin',
'form' => array(), 'url' => array(), 'plugin' => null
),
array('base' => '/', 'here' => '/', 'webroot' => '/')
));
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true));
$this->assertEqual($result, '/admin/login');

$result = Router::url(array('controller' => 'users', 'action' => 'login'));
$this->assertEqual($result, '/admin/login');

$result = Router::url(array('controller' => 'users', 'action' => 'admin_login'));
$this->assertEqual($result, '/admin/login');
}

/**
* testPassedArgsOrder method
*
Expand Down

0 comments on commit 404401b

Please sign in to comment.