mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Sort route keys in reverse length order before replacing to prevent incorrect matching
This commit is contained in:
parent
5b7c3d68f0
commit
00956110f5
1 changed files with 17 additions and 1 deletions
|
@ -518,7 +518,12 @@ class CakeRoute {
|
|||
$out = $this->template;
|
||||
|
||||
$search = $replace = array();
|
||||
foreach ($this->keys as $key) {
|
||||
$keys = $this->keys;
|
||||
|
||||
// Sort the keys in reverse order by length to prevent mismatches
|
||||
uasort($keys, array($this, '_sortKeys'));
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$string = null;
|
||||
if (isset($params[$key])) {
|
||||
$string = $params[$key];
|
||||
|
@ -537,4 +542,15 @@ class CakeRoute {
|
|||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison method for sorting keys in reverse order by length.
|
||||
*
|
||||
* @param $a
|
||||
* @param $b
|
||||
* @return int
|
||||
*/
|
||||
protected function _sortKeys($a, $b) {
|
||||
return strlen($a) > strlen($b) ? -1 : 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue