mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge pull request #452 from ltunc/named-bug
Fix urlencoded keys in named parameters.
This commit is contained in:
commit
310a7a1acf
2 changed files with 21 additions and 0 deletions
|
@ -275,6 +275,7 @@ class CakeRoute {
|
||||||
$separatorIsPresent = strpos($param, $namedConfig['separator']) !== false;
|
$separatorIsPresent = strpos($param, $namedConfig['separator']) !== false;
|
||||||
if ((!isset($this->options['named']) || !empty($this->options['named'])) && $separatorIsPresent) {
|
if ((!isset($this->options['named']) || !empty($this->options['named'])) && $separatorIsPresent) {
|
||||||
list($key, $val) = explode($namedConfig['separator'], $param, 2);
|
list($key, $val) = explode($namedConfig['separator'], $param, 2);
|
||||||
|
$key = rawurldecode($key);
|
||||||
$val = rawurldecode($val);
|
$val = rawurldecode($val);
|
||||||
$hasRule = isset($rules[$key]);
|
$hasRule = isset($rules[$key]);
|
||||||
$passIt = (!$hasRule && !$greedy) || ($hasRule && !$this->_matchNamed($val, $rules[$key], $context));
|
$passIt = (!$hasRule && !$greedy) || ($hasRule && !$this->_matchNamed($val, $rules[$key], $context));
|
||||||
|
|
|
@ -403,6 +403,26 @@ class CakeRouteTest extends CakeTestCase {
|
||||||
$this->assertEquals('something else', $result['pass'][0]);
|
$this->assertEquals('something else', $result['pass'][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that keys at named parameters are urldecoded
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testParseNamedKeyUrlDecode() {
|
||||||
|
Router::connectNamed(true);
|
||||||
|
$route = new CakeRoute('/:controller/:action/*', array('plugin' => null));
|
||||||
|
|
||||||
|
// checking /post/index/user[0]:a/user[1]:b
|
||||||
|
$result = $route->parse('/posts/index/user%5B0%5D:a/user%5B1%5D:b');
|
||||||
|
$this->assertArrayHasKey('user', $result['named']);
|
||||||
|
$this->assertEquals(array('a', 'b'), $result['named']['user']);
|
||||||
|
|
||||||
|
// checking /post/index/user[]:a/user[]:b
|
||||||
|
$result = $route->parse('/posts/index/user%5B%5D:a/user%5B%5D:b');
|
||||||
|
$this->assertArrayHasKey('user', $result['named']);
|
||||||
|
$this->assertEquals(array('a', 'b'), $result['named']['user']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that named params with null/false are excluded
|
* test that named params with null/false are excluded
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue