diff --git a/lib/Doctrine/Query/Tokenizer.php b/lib/Doctrine/Query/Tokenizer.php index 8621412ae..21423d530 100644 --- a/lib/Doctrine/Query/Tokenizer.php +++ b/lib/Doctrine/Query/Tokenizer.php @@ -33,9 +33,9 @@ * into a stateless StringUtil? class. This tokenizer should be concerned with tokenizing * DQL strings. */ -class Doctrine_Query_Tokenizer +class Doctrine_Query_Tokenizer { - + /** * tokenizeQuery * splits the given dql query into an array where keys @@ -102,7 +102,7 @@ class Doctrine_Query_Tokenizer } return $parts; } - + /** * trims brackets * @@ -143,7 +143,7 @@ class Doctrine_Query_Tokenizer public function bracketExplode($str, $d = ' ', $e1 = '(', $e2 = ')') { if (is_array($d)) { - $a = preg_split('#('.implode('|', $d).')#', $str); + $a = preg_split('#('.implode('|', $d).')#i', $str); $d = stripslashes($d[0]); } else { $a = explode($d, $str); @@ -156,7 +156,7 @@ class Doctrine_Query_Tokenizer $term[$i] = trim($val); $s1 = substr_count($term[$i], $e1); $s2 = substr_count($term[$i], $e2); - + if ($s1 == $s2) { $i++; } @@ -164,8 +164,8 @@ class Doctrine_Query_Tokenizer $term[$i] .= $d . trim($val); $c1 = substr_count($term[$i], $e1); $c2 = substr_count($term[$i], $e2); - - if ($c1 == $c2) { + + if ($c1 == $c2) { $i++; } } @@ -381,4 +381,4 @@ class Doctrine_Query_Tokenizer return $term; } -} \ No newline at end of file +} diff --git a/tests/TokenizerTestCase.php b/tests/TokenizerTestCase.php index 08235955c..d4179ab31 100644 --- a/tests/TokenizerTestCase.php +++ b/tests/TokenizerTestCase.php @@ -41,7 +41,7 @@ class Doctrine_Tokenizer_TestCase extends Doctrine_UnitTestCase public function testSqlExplode() { $tokenizer = new Doctrine_Query_Tokenizer(); - + $str = "word1 word2 word3"; $a = $tokenizer->sqlExplode($str); @@ -113,6 +113,20 @@ class Doctrine_Tokenizer_TestCase extends Doctrine_UnitTestCase $this->assertEqual($a, array('rdbms (dbal OR database)')); } + public function testBracketExplode() + { + $tokenizer = new Doctrine_Query_Tokenizer(); + + $str = 'foo.field AND bar.field'; + $a = $tokenizer->bracketExplode($str, array(' \&\& ', ' AND '), '(', ')'); + $this->assertEqual($a, array('foo.field', 'bar.field')); + + // delimiters should be case insensitive + $str = 'foo.field and bar.field'; + $a = $tokenizer->bracketExplode($str, array(' \&\& ', ' AND '), '(', ')'); + $this->assertEqual($a, array('foo.field', 'bar.field')); + } + public function testQuoteExplodedShouldQuoteArray() {