From f8f10b5309f68c0ff96c024b1baf23c6ac9f2911 Mon Sep 17 00:00:00 2001 From: Alp Kose Date: Fri, 20 Sep 2024 15:21:21 +0300 Subject: [PATCH] fix: gathered_filter to process regex correctly Removed backslash(\) escape char from shlex to avoid escaping and properly processing regex expressions. --- plugins/module_utils/panos.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/panos.py b/plugins/module_utils/panos.py index 8bce488b0..9c264e331 100644 --- a/plugins/module_utils/panos.py +++ b/plugins/module_utils/panos.py @@ -1200,6 +1200,18 @@ def _get_default_value(self, obj, key): return default_value + def _shlex_split(self, logic): + """Split string using shlex.split without escape char + + Escape char '\' is removed from shlex class to correctly process regex. + """ + lex = shlex.shlex(logic, posix=True) + lex.whitespace_split = True + lex.commenters = '' + lex.escape = '' + + return list(lex) + def matches_gathered_filter(self, item, logic): """Returns True if the item and its contents matches the logic given. @@ -1223,7 +1235,7 @@ def matches_gathered_filter(self, item, logic): evaler = [] pdepth = 0 - logic_tokens = shlex.split(logic) + logic_tokens = self._shlex_split(logic) token_iter = iter(logic_tokens) while True: end_parens = 0