AssignRenderer: Add wildcard support and render with match()

This used MatchAny explicitly, since we check against an array here.
This commit is contained in:
Markus Frosch 2020-03-05 11:52:15 +01:00
parent 3bffe6a0d9
commit e12cb9b7b9
2 changed files with 27 additions and 5 deletions

View File

@ -112,11 +112,24 @@ class AssignRenderer
protected function renderContains(FilterExpression $filter)
{
return sprintf(
'%s in %s',
$this->renderExpressionValue(json_decode($filter->getColumn())),
$filter->getExpression()
);
// Note: expression and column is flipped in this mode
$value = json_decode($filter->getColumn());
$expression = $this->renderExpressionValue($value);
$column = $filter->getExpression();
if (strpos($value, '*') !== false) {
return sprintf(
'match(%s, %s, MatchAny)',
$expression,
$column
);
} else {
return sprintf(
'%s in %s',
$expression,
$column
);
}
}
protected function renderFilterExpression(FilterExpression $filter)

View File

@ -93,6 +93,15 @@ class AssignRendererTest extends BaseTestCase
$expected,
$this->renderer($string)->renderAssign()
);
$string = json_encode('member*') . '=host.vars.some_array';
$expected = 'assign where match("member*", host.vars.some_array, MatchAny)';
$this->assertEquals(
$expected,
$this->renderer($string)->renderAssign()
);
}
public function testInArrayIsRenderedCorrectly()