diff --git a/cake/libs/string.php b/cake/libs/string.php index f3e1da4b7..e3a7d003b 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -237,7 +237,24 @@ class String extends Object { $str = str_replace($options['escape'].$options['before'], $options['before'], $str); } if ($options['clean']) { - $str = preg_replace(sprintf('/(%s[^\s]+[\s]*|[\s]*%s[^\s]+)/', $options['before'], $options['before']), '', $str); + if ($options['clean'] === true) { + $options['clean'] = array(); + } + $options['clean'] = am(array( + 'word' => '[\w,]+', + 'gap' => '[\s]*(?:(?:and|or)[\s]*)?' + ), $options); + + $kleenex = sprintf( + '/(%s%s%s|%s%s%s)/', + $options['before'], + $options['clean']['word'], + $options['clean']['gap'], + $options['clean']['gap'], + $options['before'], + $options['clean']['word'] + ); + $str = preg_replace($kleenex, '', $str); } return $str; } diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index 5f6e7db85..ecdf5ee21 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -115,6 +115,16 @@ class StringTest extends UnitTestCase { $expected = '2 and 3'; $result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true)); $this->assertEqual($result, $expected); + + $string = '":a, :b and :c"'; + $expected = '"1, 2"'; + $result = String::insert($string, array('a' => 1, 'b' => 2), array('clean' => true)); + $this->assertEqual($result, $expected); + + $string = '":a, :b and :c"'; + $expected = '"1, 2"'; + $result = String::insert($string, array('a' => 1, 'b' => 2), array('clean' => true)); + $this->assertEqual($result, $expected); } function testTokenize() {