Sort route keys in reverse length order before replacing to prevent incorrect matching

This commit is contained in:
Mike Gibson 2014-03-10 11:43:28 +00:00
parent 5b7c3d68f0
commit 00956110f5

View file

@ -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;
}
}