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

fix: use a more specific regex for jinja2 set/for statements #5514

Merged
merged 11 commits into from
Oct 28, 2024
12 changes: 10 additions & 2 deletions conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,16 @@ def find_used_variables_in_text(variant, recipe_text, selectors_only=False):
)
# TODO: this `for` regex won't catch some common cases like lists of vars, multiline
# jinja2 blocks, if filters on the for loop, etc.
for_regex = r"(?:^|[^\{])\{%\s*for\s*.*\s*in\s*" + v_regex + r"(?:[^%]*?)?%\}"
set_regex = r"(?:^|[^\{])\{%\s*set\s*.*\s*=\s*.*" + v_regex + r"(?:[^%]*?)?%\}"
for_regex = (
r"(?:^|[^\{])\{%\s*for\s*.*\s*in\s*"
+ v_regex
+ r"(?![a-zA-Z_0-9])(?:[^%]*?)?%\}"
)
set_regex = (
r"(?:^|[^\{])\{%\s*set\s*.*\s*=\s*.*"
+ v_regex
+ r"(?![a-zA-Z_0-9])(?:[^%]*?)?%\}"
)
# plain req name, no version spec. Look for end of line after name, or comment or selector
requirement_regex = rf"^\s+\-\s+{v_req_regex}\s*(?:\s[\[#]|$)"
if selectors_only:
Expand Down
19 changes: 19 additions & 0 deletions news/5514-better-jinja2-regex.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fixed regex for Jinja2 `set` / `for` statements to be more specific. (#5514)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
Loading