From: Josef 'Jeff' Sipek Date: Mon, 4 Jan 2021 17:01:28 +0000 (-0500) Subject: lib: event-filter - Make NOT operator right associative and higher precedence X-Git-Tag: 2.3.14.rc1~92 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=abe9c7585d9f83622d9380596dde6ed0b5862388;p=thirdparty%2Fdovecot%2Fcore.git lib: event-filter - Make NOT operator right associative and higher precedence 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' --- diff --git a/src/lib/event-filter-parser.y b/src/lib/event-filter-parser.y index 3900b36395..a1e4347480 100644 --- a/src/lib/event-filter-parser.y +++ b/src/lib/event-filter-parser.y @@ -142,8 +142,8 @@ static struct event_filter_node *logic(struct event_filter_parser_state *state, %type op %type expr key_value -%precedence NOT %left AND OR +%right NOT %% filter : expr { state->output = $1; }