Skip to content

Commit

Permalink
fix bug in filters parser
Browse files Browse the repository at this point in the history
Parser parsed "a or (b or c) and d" into "a or b or c and d". ("and" has higher operator precedence)

It was caused by a premature flattening of the expressions (a or (b or c) => a or b or c) while still parsing the expression. This did not regard that an operator with higher precedence than at the current point in parsing may follow next.
  • Loading branch information
westnordost committed Oct 21, 2023
1 parent e961455 commit c62e045
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ internal class BooleanExpressionBuilder<I : Matcher<T>, T> {
{
node = node.parent!!
}

node.flatten()
}

fun addValue(i: I) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,16 @@ internal class TagFilterExpressionParserTest {
notMatches(mapOfKeys("a", "b", "c", "d"), expr)
}


@Test fun brackets_are_not_dissolved_illegally() {
val expr = "a or (b or c) and !d"
matches(mapOfKeys("a"), expr)
matches(mapOfKeys("a", "d"), expr)
matches(mapOfKeys("b"), expr)
matches(mapOfKeys("c"), expr)
notMatches(mapOfKeys("c", "d"), expr)
notMatches(mapOfKeys("b", "d"), expr)
matches(mapOfKeys("a", "c", "d"), expr)
}

@Test fun fail_on_placeholder_not_closed() {
shouldFail("{my placeholder")
Expand Down

0 comments on commit c62e045

Please sign in to comment.