Skip to content

Commit

Permalink
filter: Fix whitepsace sanitation when expression is an array
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Oct 1, 2014
1 parent 56a1af4 commit ebde422
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Icinga/Data/Filter/Filter.php
Expand Up @@ -132,7 +132,7 @@ public static function where($col, $filter)
public static function expression($col, $op, $expression)
{
$col = trim($col);
$expression = trim($expression);
$expression = is_array($expression) ? array_map('trim', $expression) : trim($expression);
switch ($op) {
case '=': return new FilterMatch($col, $op, $expression);
case '<': return new FilterLessThan($col, $op, $expression);
Expand Down
2 changes: 2 additions & 0 deletions test/php/library/Icinga/Data/Filter/FilterTest.php
Expand Up @@ -204,9 +204,11 @@ public function testLeadingAndTrailingWhitespacesSanitizing()
$columnHasWhitespaces = Filter::where(' host ', 'localhost');
$expressionHasWhitespaces = Filter::where('host', ' localhost ');
$bothHaveWhitespaces = Filter::fromQueryString(' host = localhost ');
$withArray = Filter::where(' host ', array(' no match ', ' localhost '));
$this->assertTrue($columnHasWhitespaces->matches($this->sampleData[0]));
$this->assertTrue($expressionHasWhitespaces->matches($this->sampleData[0]));
$this->assertTrue($bothHaveWhitespaces->matches($this->sampleData[0]));
$this->assertTrue($withArray->matches($this->sampleData[0]));
}

private function row($idx)
Expand Down

0 comments on commit ebde422

Please sign in to comment.