From 3db8b860d1fadb6cfd803041c36976f23f193495 Mon Sep 17 00:00:00 2001 From: the_undefined Date: Tue, 13 May 2008 21:22:10 +0000 Subject: [PATCH] Fixed another String::tokenize bug, closes #4627 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6852 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/string.php | 22 ++++++++++++++++++---- cake/tests/cases/libs/string.test.php | 4 ++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cake/libs/string.php b/cake/libs/string.php index 400189af1..f3e1da4b7 100644 --- a/cake/libs/string.php +++ b/cake/libs/string.php @@ -138,6 +138,7 @@ class String extends Object { $buffer = ''; $results = array(); $length = strlen($data); + $open = false; while ($offset <= $length) { $tmpOffset = -1; @@ -155,10 +156,23 @@ class String extends Object { } else { $buffer .= $data{$tmpOffset}; } - if ($data{$tmpOffset} == $leftBound) { - $depth++; - } elseif ($data{$tmpOffset} == $rightBound) { - $depth--; + if ($leftBound != $rightBound) { + if ($data{$tmpOffset} == $leftBound) { + $depth++; + } + if ($data{$tmpOffset} == $rightBound) { + $depth--; + } + } else { + if ($data{$tmpOffset} == $leftBound) { + if (!$open) { + $depth++; + $open = true; + } else { + $depth--; + $open = false; + } + } } $offset = ++$tmpOffset; } else { diff --git a/cake/tests/cases/libs/string.test.php b/cake/tests/cases/libs/string.test.php index d6163d128..5f6e7db85 100644 --- a/cake/tests/cases/libs/string.test.php +++ b/cake/tests/cases/libs/string.test.php @@ -133,6 +133,10 @@ class StringTest extends UnitTestCase { $result = String::tokenize('"single tag"', ' ', '"', '"'); $expected = array('"single tag"'); $this->assertEqual($expected, $result); + + $result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"'); + $expected = array('tagA', '"single tag"', 'tagB'); + $this->assertEqual($expected, $result); } } ?> \ No newline at end of file