From 6f64efb3424d83e98ae4073cf90723686d11eb4a Mon Sep 17 00:00:00 2001 From: the_undefined Date: Tue, 13 May 2008 02:05:07 +0000 Subject: [PATCH] Fixed a String::tokenize bug for a single enclosed item, closes #4627 Added basic test coverage for String::tokenize git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6827 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/string.php | 3 +-- cake/tests/cases/libs/string.test.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cake/libs/string.php b/cake/libs/string.php index ba02e569a..400189af1 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -157,8 +157,7 @@ class String extends Object { } if ($data{$tmpOffset} == $leftBound) { $depth++; - } - if ($data{$tmpOffset} == $rightBound) { + } elseif ($data{$tmpOffset} == $rightBound) { $depth--; } $offset = ++$tmpOffset; diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index a756c12d5..d6163d128 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -116,5 +116,23 @@ class StringTest extends UnitTestCase { $result = String::insert($string, array('b' => 2, 'c' => 3), array('clean' => true)); $this->assertEqual($result, $expected); } + + function testTokenize() { + $result = String::tokenize('A,(short,boring test)'); + $expected = array('A', '(short,boring test)'); + $this->assertEqual($result, $expected); + + $result = String::tokenize('A,(short,more interesting( test)'); + $expected = array('A', '(short,more interesting( test)'); + $this->assertEqual($result, $expected); + + $result = String::tokenize('A,(short,very interesting( test))'); + $expected = array('A', '(short,very interesting( test))'); + $this->assertEqual($result, $expected); + + $result = String::tokenize('"single tag"', ' ', '"', '"'); + $expected = array('"single tag"'); + $this->assertEqual($expected, $result); + } } ?> \ No newline at end of file