]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: event-filter - Make NOT operator right associative and higher precedence
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Mon, 4 Jan 2021 17:01:28 +0000 (12:01 -0500)
committerJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Mon, 4 Jan 2021 17:01:28 +0000 (12:01 -0500)
For example, consider the filter:

    event=* AND
    NOT event=foo AND
    NOT event=bar AND
    NOT event=baz

The "NOT" operator is supposed to be bound to the comparisons to the
immediate right.  That is, it supposed to be equivalent to:

    event=* AND
    (NOT event=foo) AND
    (NOT event=bar) AND
    (NOT event=baz)

Both of these should produce the following parse tree:

    AND
      AND
        AND
          EQ EVENT '*'
          NOT
            EQ EVENT 'foo'
        NOT
          EQ EVENT 'bar'
      NOT
        EQ EVENT 'baz'

Instead, before this commit, the NOTs were getting bound to the entire
sub-expression to the right.  Therefore, the original filter expression
was being parsed as if it were:

    event=* AND
    NOT (event=foo AND
         NOT (event=bar AND
              NOT event=baz))

Which produced the following parse tree:

    AND
      EQ EVENT '*'
      NOT
        AND
          EQ EVENT 'foo'
          NOT
            AND
              EQ EVENT 'bar'
              NOT
                EQ EVENT 'baz'

src/lib/event-filter-parser.y

index 3900b36395d9940f463a65268b901acacb9290c3..a1e4347480ae9fb738fe2d0878534e509aacc1b8 100644 (file)
@@ -142,8 +142,8 @@ static struct event_filter_node *logic(struct event_filter_parser_state *state,
 %type <op> op
 %type <node> expr key_value
 
-%precedence NOT
 %left AND OR
+%right NOT
 
 %%
 filter : expr                  { state->output = $1; }