Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters: fix the precedence of ';' #122

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/cfg-grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
/* this is a placeholder for unit tests, must be the latest & largest */
%token LL_CONTEXT_MAX 27


%left ';'

/* operators in the filter language, the order of this determines precedence */
%right KW_ASSIGN 9000
%right '?' ':'
Expand Down
2 changes: 0 additions & 2 deletions lib/filter/filter-expr-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ _translate_number_literals(CfgLexer *lexer, gint compare_mode, LogTemplate *expr
%token KW_PROGRAM
%token KW_IN_LIST

%left ';'

%type <node> filter_expr
%type <node> filter_simple_expr
%type <node> filter_plugin
Expand Down
1 change: 1 addition & 0 deletions tests/copyright/policy
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ tests/light/functional_tests/logpath/test_conditionals\.py
tests/light/functional_tests/logpath/test_midpoint_destinations\.py
tests/light/functional_tests/value-pairs/test_value_pairs\.py
tests/light/functional_tests/templates/test_template_stmt\.py
tests/light/functional_tests/filters/test_multiple_filters\.py
tests/light/functional_tests/filterx/test_filterx\.py
tests/light/functional_tests/filterx/test_filterx_scope\.py
tests/light/functional_tests/parsers/metrics-probe/test_metrics_probe\.py
Expand Down
1 change: 1 addition & 0 deletions tests/light/functional_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EXTRA_DIST += \
tests/light/functional_tests/destination_drivers/unix_stream_destination/test_unix_stream_destination.py \
tests/light/functional_tests/filters/rate-limit/test_rate_limit_filter_acceptance.py \
tests/light/functional_tests/filters/test_filter_reference.py \
tests/light/functional_tests/filters/test_multiple_filters.py \
tests/light/functional_tests/logpath/__init__.py \
tests/light/functional_tests/logpath/test_conditionals.py \
tests/light/functional_tests/logpath/test_flags_catch_all.py \
Expand Down
70 changes: 70 additions & 0 deletions tests/light/functional_tests/filters/test_multiple_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
#############################################################################
# Copyright (c) 2024 Attila Szakacs
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# As an additional exemption you are allowed to compile & link against the
# OpenSSL libraries as published by the OpenSSL project. See the file
# COPYING for details.
#
#############################################################################
from src.syslog_ng_config.renderer import render_statement


def test_multiple_filters_implicit_and(config, syslog_ng):
file_true = config.create_file_destination(file_name="dest-true.log", template="\"$MSG\\n\"")
file_false = config.create_file_destination(file_name="dest-false.log", template="\"$MSG\\n\"")

preamble = f"""
@version: {config.get_version()}
options {{ stats(level(1)); }};
source genmsg {{
example-msg-generator(num(1) template("MESSAGE"));
example-msg-generator(num(1) template("foobar"));
}};
filter f_filter {{
not program("xyz");
message("MESSAGE");
}};
destination dest_true {{
{render_statement(file_true)};
}};
destination dest_false {{
{render_statement(file_false)};
}};
log {{
source(genmsg);
if {{
filter(f_filter);
destination(dest_true);
}} else {{
destination(dest_false);
}};
}};
"""
config.set_raw_config(preamble)
syslog_ng.start(config)

assert file_true.get_stats()["processed"] == 1
assert file_false.get_stats()["processed"] == 1

assert "MESSAGE" in file_true.read_log()
assert "foobar" in file_false.read_log()
Loading