From fe38c428c2612bfea4e9d99891b82dca23125ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0pl=C3=ADchal?= Date: Tue, 23 Jan 2024 16:19:47 +0100 Subject: [PATCH] Support escaping `|` and `&` in `utils.filter()` Add support for escaping boolean operators using the back slash character `\` to allow for example regular expression grouping. --- fmf/utils.py | 17 ++++++++++++++--- tests/unit/test_utils.py | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/fmf/utils.py b/fmf/utils.py index 5e269aef..078bc38e 100644 --- a/fmf/utils.py +++ b/fmf/utils.py @@ -222,6 +222,13 @@ def filter(filter, data, sensitive=True, regexp=False, name=None): tag: Tier1 | tag: Tier2 | tag: Tier3 category: Sanity, Security & tag: -destructive + Use the back slash character ``\\`` to escape the boolean + operators if you need to specify them as part of the filter + expressions:: + + tag: Tier(1\\|2) + text: Q\\&A + Note that multiple comma-separated values can be used as a syntactic sugar to shorten the filter notation:: @@ -322,7 +329,10 @@ def check_clause(clause): # E.g. clause = 'tag: A, B & tag: C & tag: -D' # Split into individual literals by dimension literals = dict() - for literal in re.split(r"\s*&\s*", clause): + + for literal in re.split(r"\s*(?