diff --git a/cake/libs/string.php b/cake/libs/string.php index 978f3163e04..b9ae4be1bbb 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -240,6 +240,7 @@ function insert($str, $data, $options = array()) { $hashKeys = array_map('md5', array_keys($data)); $tempData = array_combine(array_keys($data), array_values($hashKeys)); + krsort($tempData); foreach ($tempData as $key => $hashVal) { $key = sprintf($format, preg_quote($key, '/')); $str = preg_replace($key, $hashVal, $str); @@ -323,4 +324,4 @@ function cleanInsert($str, $options) { return $str; } } -?> \ No newline at end of file +?> diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index 738eba27047..7c47f97e7ca 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -197,6 +197,26 @@ function testInsert() { $result = String::insert('?-pended result', array('Pre')); $expected = "Pre-pended result"; $this->assertEqual($result, $expected); + + $string = 'switching :timeout / :timeout_count'; + $expected = 'switching 5 / 10'; + $result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10)); + $this->assertEqual($result, $expected); + + $string = 'switching :timeout / :timeout_count'; + $expected = 'switching 5 / 10'; + $result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5)); + $this->assertEqual($result, $expected); + + $string = 'switching :timeout_count by :timeout'; + $expected = 'switching 10 by 5'; + $result = String::insert($string, array('timeout' => 5, 'timeout_count' => 10)); + $this->assertEqual($result, $expected); + + $string = 'switching :timeout_count by :timeout'; + $expected = 'switching 10 by 5'; + $result = String::insert($string, array('timeout_count' => 10, 'timeout' => 5)); + $this->assertEqual($result, $expected); } /** * test Clean Insert @@ -253,4 +273,4 @@ function testTokenize() { $this->assertEqual($expected, $result); } } -?> \ No newline at end of file +?>