diff --git a/library/Director/Objects/HostApplyMatches.php b/library/Director/Objects/HostApplyMatches.php index 932f343b..cd505467 100644 --- a/library/Director/Objects/HostApplyMatches.php +++ b/library/Director/Objects/HostApplyMatches.php @@ -103,15 +103,7 @@ class HostApplyMatches protected static function fixFilterColumns(Filter $filter) { if ($filter->isExpression()) { - /** @var FilterExpression $filter */ - $col = $filter->getColumn(); - if (substr($col, 0, 5) === 'host.') { - $filter->setColumn($col = substr($col, 5)); - } - if (array_key_exists($col, self::$columnMap)) { - $filter->setColumn(self::$columnMap[$col]); - } - $filter->setExpression(json_decode($filter->getExpression())); + static::fixFilterExpressionColumn($filter); } else { foreach ($filter->filters() as $sub) { static::fixFilterColumns($sub); @@ -119,6 +111,32 @@ class HostApplyMatches } } + protected static function fixFilterExpressionColumn(FilterExpression $filter) + { + if (static::columnIsJson($filter)) { + $column = $filter->getExpression(); + $filter->setExpression($filter->getColumn()); + $filter->setColumn($column); + } + + /** @var FilterExpression $filter */ + $col = $filter->getColumn(); + if (substr($col, 0, 5) === 'host.') { + $filter->setColumn($col = substr($col, 5)); + } + + if (array_key_exists($col, self::$columnMap)) { + $filter->setColumn(self::$columnMap[$col]); + } + $filter->setExpression(json_decode($filter->getExpression())); + } + + protected static function columnIsJson(FilterExpression $filter) + { + $col = $filter->getColumn(); + return strlen($col) && $col[0] === '"'; + } + protected static function flattenVars(& $object, $key = 'vars') { if (property_exists($object, 'vars')) { diff --git a/test/php/library/Director/Objects/HostApplyMatchesTest.php b/test/php/library/Director/Objects/HostApplyMatchesTest.php index 4811044b..3c7f4328 100644 --- a/test/php/library/Director/Objects/HostApplyMatchesTest.php +++ b/test/php/library/Director/Objects/HostApplyMatchesTest.php @@ -64,6 +64,21 @@ class HostApplyMatchesTest extends BaseTestCase ); } + public function testArrayVariableMatches() + { + $matcher = HostApplyMatches::prepare($this->sampleHost()); + $this->assertTrue( + $matcher->matchesFilter( + Filter::fromQueryString('%22Amazing%22=host.vars.tags') + ) + ); + $this->assertFalse( + $matcher->matchesFilter( + Filter::fromQueryString('%22Amazingg%22=host.vars.tags') + ) + ); + } + protected function sampleHost() { return IcingaHost::create(array(