mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
commit
2f98733944
@ -12,7 +12,6 @@ class FilterExpression extends Filter
|
|||||||
public function __construct($column, $sign, $expression)
|
public function __construct($column, $sign, $expression)
|
||||||
{
|
{
|
||||||
$column = trim($column);
|
$column = trim($column);
|
||||||
$expression = is_array($expression) ? array_map('trim', $expression) : trim($expression);
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
$this->sign = $sign;
|
$this->sign = $sign;
|
||||||
$this->expression = $expression;
|
$this->expression = $expression;
|
||||||
|
@ -231,10 +231,11 @@ class FilterEditor extends AbstractWidget
|
|||||||
if ($searchCol === null) {
|
if ($searchCol === null) {
|
||||||
throw new Exception('Cannot search here');
|
throw new Exception('Cannot search here');
|
||||||
}
|
}
|
||||||
|
$search = ltrim($search);
|
||||||
$filter = $this->mergeRootExpression($filter, $searchCol, '=', "*$search*");
|
$filter = $this->mergeRootExpression($filter, $searchCol, '=', "*$search*");
|
||||||
} else {
|
} else {
|
||||||
list($k, $v) = preg_split('/=/', $search);
|
list($k, $v) = preg_split('/=/', $search);
|
||||||
$filter = $this->mergeRootExpression($filter, $k, '=', $v);
|
$filter = $this->mergeRootExpression($filter, trim($k), '=', ltrim($v));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (false === $this->resetSearchColumns($filter)) {
|
if (false === $this->resetSearchColumns($filter)) {
|
||||||
@ -242,6 +243,7 @@ class FilterEditor extends AbstractWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filters = array();
|
$filters = array();
|
||||||
|
$search = ltrim($search);
|
||||||
foreach ($this->searchColumns as $searchColumn) {
|
foreach ($this->searchColumns as $searchColumn) {
|
||||||
$filters[] = Filter::expression($searchColumn, '=', "*$search*");
|
$filters[] = Filter::expression($searchColumn, '=', "*$search*");
|
||||||
}
|
}
|
||||||
|
@ -198,16 +198,53 @@ class FilterTest extends BaseTestCase
|
|||||||
$this->assertNotEquals((string) $c, (string) $d);
|
$this->assertNotEquals((string) $c, (string) $d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLeadingAndTrailingWhitespacesSanitizing()
|
public function testLeadingAndTrailingWhitespaces()
|
||||||
{
|
{
|
||||||
$columnHasWhitespaces = Filter::where(' host ', 'localhost');
|
$columnWithWhitespaces = Filter::where(' host ', 'localhost');
|
||||||
$expressionHasWhitespaces = Filter::where('host', ' localhost ');
|
$this->assertTrue($columnWithWhitespaces->matches((object) array(
|
||||||
$bothHaveWhitespaces = Filter::fromQueryString(' host = localhost ');
|
'host' => 'localhost'
|
||||||
$withArray = Filter::where(' host ', array(' no match ', ' localhost '));
|
)),
|
||||||
$this->assertTrue($columnHasWhitespaces->matches($this->sampleData[0]));
|
'Filter doesn\'t remove leading and trailing whitespaces from columns'
|
||||||
$this->assertTrue($expressionHasWhitespaces->matches($this->sampleData[0]));
|
);
|
||||||
$this->assertTrue($bothHaveWhitespaces->matches($this->sampleData[0]));
|
$expressionWithLeadingWhitespaces = Filter::where('host', ' localhost');
|
||||||
$this->assertTrue($withArray->matches($this->sampleData[0]));
|
$this->assertTrue($expressionWithLeadingWhitespaces->matches((object) array(
|
||||||
|
'host' => ' localhost'
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take leading whitespaces of expressions into account'
|
||||||
|
);
|
||||||
|
$this->assertFalse($expressionWithLeadingWhitespaces->matches((object) array(
|
||||||
|
'host' => ' localhost '
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take trailing whitespaces of expressions into account'
|
||||||
|
);
|
||||||
|
$expressionWithTrailingWhitespaces = Filter::where('host', 'localhost ');
|
||||||
|
$this->assertTrue($expressionWithTrailingWhitespaces->matches((object) array(
|
||||||
|
'host' => 'localhost '
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take trailing whitespaces of expressions into account'
|
||||||
|
);
|
||||||
|
$this->assertFalse($expressionWithTrailingWhitespaces->matches((object) array(
|
||||||
|
'host' => ' localhost '
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take leading whitespaces of expressions into account'
|
||||||
|
);
|
||||||
|
$expressionWithLeadingAndTrailingWhitespaces = Filter::where('host', ' localhost ');
|
||||||
|
$this->assertTrue($expressionWithLeadingAndTrailingWhitespaces->matches((object) array(
|
||||||
|
'host' => ' localhost '
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take leading and trailing whitespaces of expressions into account'
|
||||||
|
);
|
||||||
|
$this->assertFalse($expressionWithLeadingAndTrailingWhitespaces->matches((object) array(
|
||||||
|
'host' => ' localhost '
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take leading and trailing whitespaces of expressions into account'
|
||||||
|
);
|
||||||
|
$queryStringWithWhitespaces = Filter::fromQueryString(' host = localhost ');
|
||||||
|
$this->assertTrue($queryStringWithWhitespaces->matches((object) array(
|
||||||
|
'host' => ' localhost '
|
||||||
|
)),
|
||||||
|
'Filter doesn\'t take leading and trailing whitespaces of expressions in query strings into account'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function row($idx)
|
private function row($idx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user