mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fix issue in Router with prefixes.
Prefixes should not be interpreted as named parameters. Fixes #2269
This commit is contained in:
parent
0f299a1542
commit
cb49b242ae
2 changed files with 17 additions and 2 deletions
|
@ -388,6 +388,7 @@ class CakeRoute {
|
|||
}
|
||||
|
||||
$namedConfig = Router::namedConfig();
|
||||
$prefixes = Router::prefixes();
|
||||
$greedyNamed = $namedConfig['greedyNamed'];
|
||||
$allowedNamedParams = $namedConfig['rules'];
|
||||
|
||||
|
@ -421,7 +422,8 @@ class CakeRoute {
|
|||
// pull out named params if named params are greedy or a rule exists.
|
||||
if (
|
||||
($greedyNamed || isset($allowedNamedParams[$key])) &&
|
||||
($value !== false && $value !== null)
|
||||
($value !== false && $value !== null) &&
|
||||
(!in_array($key, $prefixes))
|
||||
) {
|
||||
$named[$key] = $value;
|
||||
continue;
|
||||
|
|
|
@ -606,7 +606,7 @@ class CakeRouteTest extends CakeTestCase {
|
|||
'fish' => 'trout'
|
||||
)
|
||||
);
|
||||
$this->assertEquals($expected, $result, 'Fish should be parsed, as action == index');
|
||||
$this->assertEquals($expected, $result, 'Fizz should be parsed, as controller == comments|other');
|
||||
|
||||
$result = $route->parse('/comments/index/wibble:spin/fish:trout/fizz:buzz');
|
||||
$expected = array(
|
||||
|
@ -665,6 +665,19 @@ class CakeRouteTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result, 'Greedy named grabs everything, rules are followed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Having greedNamed enabled should not capture routing.prefixes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMatchGreedyNamedExcludesPrefixes() {
|
||||
Configure::write('Routing.prefixes', array('admin'));
|
||||
Router::reload();
|
||||
|
||||
$route = new CakeRoute('/sales/*', array('controller' => 'sales', 'action' => 'index'));
|
||||
$this->assertFalse($route->match(array('controller' => 'sales', 'action' => 'index', 'admin' => 1)), 'Greedy named consume routing prefixes.');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that parsing array format named parameters works
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue