Skip to content
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
1 change: 1 addition & 0 deletions changelog/65722.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle regular expressions which do not not use grouping
6 changes: 6 additions & 0 deletions salt/utils/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ def regex_search(txt, rgx, ignorecase=False, multiline=False):
obj = re.search(rgx, txt, flag)
if not obj:
return
# Handle regular expressions which do not not use grouping
if obj and not obj.groups():
return (obj.group(),)
return obj.groups()


Expand Down Expand Up @@ -495,6 +498,9 @@ def regex_match(txt, rgx, ignorecase=False, multiline=False):
obj = re.match(rgx, txt, flag)
if not obj:
return
# Handle regular expressions which do not use grouping
if obj and not obj.groups():
return (obj.group(),)
return obj.groups()


Expand Down
22 changes: 22 additions & 0 deletions tests/pytests/functional/modules/state/test_jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ def _filter_id(value):
- text: {{ result }}
""",
),
Filter(
name="regex_match_ungrouped",
expected={"ret": "('1.abc',)"},
sls="""
{% set result = '1.abc' | regex_match('^1.abc$') %}
test:
module.run:
- name: test.echo
- text: {{ result }}
""",
),
Filter(
name="regex_match_no_match",
expected={"ret": "None"},
Expand Down Expand Up @@ -700,6 +711,17 @@ def _filter_id(value):
- text: {{ result }}
""",
),
Filter(
name="regex_search_ungrouped",
expected={"ret": "('1.abc',)"},
sls="""
{% set result = '1.abc' | regex_search('^1.abc$') %}
test:
module.run:
- name: test.echo
- text: {{ result }}
""",
),
Filter(
name="regex_search_no_match",
expected={"ret": "None"},
Expand Down