From 6dbb8690adb1fad80d5354b8d8735fbcfdad9783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 13 Oct 2009 10:45:17 -0430 Subject: [PATCH] Fixing error in String::insert where string that contained a question mark were not propperly replaced --- cake/libs/string.php | 2 +- cake/tests/cases/libs/string.test.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cake/libs/string.php b/cake/libs/string.php index b8187279e..67bed6768 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -236,7 +236,7 @@ class String { ); } - if (strpos($str, '?') !== false) { + if (strpos($str, '?') !== false && is_numeric(key($data))) { $offset = 0; while (($pos = strpos($str, '?', $offset)) !== false) { $val = array_shift($data); diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index df1066012..52ac2867c 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -279,6 +279,13 @@ class StringTest extends CakeTestCase { $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); + } } ?> \ No newline at end of file