Skip to content

Commit f8f10b5

Browse files
committed
fix: gathered_filter to process regex correctly
Removed backslash(\) escape char from shlex to avoid escaping and properly processing regex expressions.
1 parent 0fdd990 commit f8f10b5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

plugins/module_utils/panos.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,18 @@ def _get_default_value(self, obj, key):
12001200

12011201
return default_value
12021202

1203+
def _shlex_split(self, logic):
1204+
"""Split string using shlex.split without escape char
1205+
1206+
Escape char '\' is removed from shlex class to correctly process regex.
1207+
"""
1208+
lex = shlex.shlex(logic, posix=True)
1209+
lex.whitespace_split = True
1210+
lex.commenters = ''
1211+
lex.escape = ''
1212+
1213+
return list(lex)
1214+
12031215
def matches_gathered_filter(self, item, logic):
12041216
"""Returns True if the item and its contents matches the logic given.
12051217
@@ -1223,7 +1235,7 @@ def matches_gathered_filter(self, item, logic):
12231235
evaler = []
12241236

12251237
pdepth = 0
1226-
logic_tokens = shlex.split(logic)
1238+
logic_tokens = self._shlex_split(logic)
12271239
token_iter = iter(logic_tokens)
12281240
while True:
12291241
end_parens = 0

0 commit comments

Comments
 (0)