Commit 7e0a902a authored by dbrewer's avatar dbrewer

Added test case to demonstrate that delimiters in

Doctrine_Query_Tokenizer::bracketExplode() were case sensitive, and 
changed tokenizer to make them case insensitive.
parent 227c1c3c
......@@ -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
}
......@@ -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()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment