filter: Fix whitepsace sanitation when expression is an array

This commit is contained in:
Eric Lippmann 2014-10-01 04:00:43 +02:00
parent 56a1af47e7
commit ebde422824
2 changed files with 3 additions and 1 deletions

View File

@ -132,7 +132,7 @@ abstract class Filter
public static function expression($col, $op, $expression) public static function expression($col, $op, $expression)
{ {
$col = trim($col); $col = trim($col);
$expression = trim($expression); $expression = is_array($expression) ? array_map('trim', $expression) : trim($expression);
switch ($op) { switch ($op) {
case '=': return new FilterMatch($col, $op, $expression); case '=': return new FilterMatch($col, $op, $expression);
case '<': return new FilterLessThan($col, $op, $expression); case '<': return new FilterLessThan($col, $op, $expression);

View File

@ -204,9 +204,11 @@ class FilterTest extends BaseTestCase
$columnHasWhitespaces = Filter::where(' host ', 'localhost'); $columnHasWhitespaces = Filter::where(' host ', 'localhost');
$expressionHasWhitespaces = Filter::where('host', ' localhost '); $expressionHasWhitespaces = Filter::where('host', ' localhost ');
$bothHaveWhitespaces = Filter::fromQueryString(' host = localhost '); $bothHaveWhitespaces = Filter::fromQueryString(' host = localhost ');
$withArray = Filter::where(' host ', array(' no match ', ' localhost '));
$this->assertTrue($columnHasWhitespaces->matches($this->sampleData[0])); $this->assertTrue($columnHasWhitespaces->matches($this->sampleData[0]));
$this->assertTrue($expressionHasWhitespaces->matches($this->sampleData[0])); $this->assertTrue($expressionHasWhitespaces->matches($this->sampleData[0]));
$this->assertTrue($bothHaveWhitespaces->matches($this->sampleData[0])); $this->assertTrue($bothHaveWhitespaces->matches($this->sampleData[0]));
$this->assertTrue($withArray->matches($this->sampleData[0]));
} }
private function row($idx) private function row($idx)