Browse files

Fixed bug related to the order in which some replacement take place

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8138 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent 9491e46 commit bf2829a896edf7c663d6c130d1d789862a9756cc @felixge felixge committed Apr 9, 2009
Showing with 7 additions and 0 deletions.
  1. +2 −0 cake/libs/string.php
  2. +5 −0 cake/tests/cases/libs/string.test.php
View
2 cake/libs/string.php
@@ -237,6 +237,8 @@ function insert($str, $data, $options = array()) {
$str = substr_replace($str, $val, $pos, 1);
}
} else {
+ asort($data);
+
$hashKeys = array_map('md5', array_keys($data));
$tempData = array_combine(array_keys($data), array_values($hashKeys));
foreach ($tempData as $key => $hashVal) {
View
5 cake/tests/cases/libs/string.test.php
@@ -88,6 +88,11 @@ function testInsert() {
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('format' => '/([\d])([\d])%s\\2\\1/'));
$this->assertEqual($result, $expected);
+ $string = ':web :web_site';
+ $expected = 'www http';
+ $result = String::insert($string, array('web' => 'www', 'web_site' => 'http'));
+ $this->assertEqual($result, $expected);
+
$string = '2 + 2 = <sum. Cake is <adjective>.';
$expected = '2 + 2 = <sum. Cake is yummy.';
$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'), array('before' => '<', 'after' => '>'));

0 comments on commit bf2829a

Please sign in to comment.