fixes #4923, argSeparator in Router::connectNamed()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7206 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-17 15:46:49 +00:00
parent 193959ebf3
commit 82f4a03385
2 changed files with 16 additions and 3 deletions

View file

@ -249,7 +249,7 @@ class Router extends Object {
$_this =& Router::getInstance();
if (isset($options['argSeparator'])) {
$options['separator'] = $options['argSeparator'];
$_this->named['separator'] = $options['argSeparator'];
unset($options['argSeparator']);
}
@ -1302,9 +1302,8 @@ class Router extends Object {
continue;
}
$param = $_this->stripEscape($param);
if ((!isset($options['named']) || !empty($options['named'])) && strpos($param, $_this->named['separator'])) {
if ((!isset($options['named']) || !empty($options['named'])) && strpos($param, $_this->named['separator']) !== false) {
list($key, $val) = explode($_this->named['separator'], $param, 2);
$hasRule = isset($rules[$key]);
$passIt = (!$hasRule && !$greedy) || ($hasRule && !Router::matchNamed($key, $val, $rules[$key], $context));
if ($passIt) {

View file

@ -1032,6 +1032,20 @@ class RouterTest extends UnitTestCase {
$named = Router::connectNamed(false, array('default' => true));
$this->assertFalse($named['greedy']);
$this->assertEqual(array_keys($named['rules']), $named['default']);
Router::reload();
Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar'));
Router::connectNamed(array(), array('argSeparator' => '='));
$result = Router::parse('/foo/param1=value1/param2=value2');
$expected = array('pass' => array(), 'named' => array('param1' => 'value1', 'param2' => 'value2'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null);
$this->assertEqual($result, $expected);
Router::reload();
Router::connect('/controller/action/*', array('controller' => 'controller', 'action' => 'action'), array('named' => array('param1' => 'value[\d]')));
Router::connectNamed(array(), array('greedy' => false, 'argSeparator' => '='));
$result = Router::parse('/controller/action/param1=value1/param2=value2');
$expected = array('pass' => array('param2=value2'), 'named' => array('param1' => 'value1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null);
$this->assertEqual($result, $expected);
}
/**
* testNamedArgsUrlGeneration method