From 72c37d429ee58cd644444aea23b5540483901e93 Mon Sep 17 00:00:00 2001 From: the_undefined Date: Wed, 14 May 2008 16:31:44 +0000 Subject: [PATCH] Improved String::insert by support placeholders with after sequence during cleanup git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6869 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/string.php | 10 ++++++---- cake/tests/cases/libs/string.test.php | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cake/libs/string.php b/cake/libs/string.php index e3a7d003b..18ca86fc5 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -246,13 +246,15 @@ class String extends Object { ), $options); $kleenex = sprintf( - '/(%s%s%s|%s%s%s)/', - $options['before'], + '/(%s%s%s%s|%s%s%s%s)/', + preg_quote($options['before'], '/'), $options['clean']['word'], + preg_quote($options['after'], '/'), $options['clean']['gap'], $options['clean']['gap'], - $options['before'], - $options['clean']['word'] + preg_quote($options['before'], '/'), + $options['clean']['word'], + preg_quote($options['after'], '/') ); $str = preg_replace($kleenex, '', $str); } diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index ecdf5ee21..00eb600b0 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -121,9 +121,9 @@ class StringTest extends UnitTestCase { $result = String::insert($string, array('a' => 1, 'b' => 2), array('clean' => true)); $this->assertEqual($result, $expected); - $string = '":a, :b and :c"'; + $string = '"${a}, ${b} and ${c}"'; $expected = '"1, 2"'; - $result = String::insert($string, array('a' => 1, 'b' => 2), array('clean' => true)); + $result = String::insert($string, array('a' => 1, 'b' => 2), array('before' => '${', 'after' => '}', 'clean' => true)); $this->assertEqual($result, $expected); }