Skip to content

Commit

Permalink
Fixed bug related to the order in which some replacement take place
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8138 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
felixge committed Apr 9, 2009
1 parent 9491e46 commit bf2829a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cake/libs/string.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions cake/tests/cases/libs/string.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '>'));
Expand Down

0 comments on commit bf2829a

Please sign in to comment.