Permalink
Browse files

Fixing error in String::insert where string that contained a question…

… mark were not propperly replaced
  • Loading branch information...
1 parent 24c82e7 commit 6dbb8690adb1fad80d5354b8d8735fbcfdad9783 @lorenzo lorenzo committed with markstory Oct 13, 2009
Showing with 8 additions and 1 deletion.
  1. +1 −1 cake/libs/string.php
  2. +7 −0 cake/tests/cases/libs/string.test.php
View
@@ -236,7 +236,7 @@ function insert($str, $data, $options = array()) {
);
}
- if (strpos($str, '?') !== false) {
+ if (strpos($str, '?') !== false && is_numeric(key($data))) {
$offset = 0;
while (($pos = strpos($str, '?', $offset)) !== false) {
$val = array_shift($data);
@@ -279,6 +279,13 @@ function testTokenize() {
$expected = array('tagA', '"single tag"', 'tagB');
$this->assertEqual($expected, $result);
}
+
+ function testReplaceWithQuestionMarkInString() {
+ $string = ':a, :b and :c?';
+ $expected = '2 and 3?';
+ $result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true));
+ $this->assertEqual($expected, $result);
+ }
}
?>

0 comments on commit 6dbb869

Please sign in to comment.