fix(workflows): quote-aware interpolation so a literal }} in a filter arg doesn't break multi-expression templates#3307
Open
Quratulain-bilal wants to merge 1 commit into
Conversation
… arg doesn't break multi-expression templates github#3208/github#3228 hardened the single-expression fast path (_is_single_expression) so a literal {{ or }} inside a string argument like `| default('}}')` stays on the typed path. the multi-expression interpolation path was left on the old _EXPR_PATTERN regex, whose non-greedy `(.+?)}}` body stops at the first }} regardless of quoting. so a multi-expression template with a literal }} in any block captured a truncated body, hit the filter parser malformed, and raised ValueError. e.g. `{{ inputs.name }}: {{ inputs.missing | default('}}') }}` raised instead of interpolating. replace _EXPR_PATTERN.sub with _interpolate_expressions, which scans each block for a }} outside string literals - the same quote handling _is_single_expression already uses. plain-value passthrough (a literal }} in a resolved value, not an expression) is unchanged. add regression tests for a literal }} in the second block and in the first block, plus a literal {{ guard.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes workflow template interpolation for multi-expression strings by replacing the regex-based {{ ... }} substitution with a quote-aware scan, preventing a literal }} inside a quoted filter argument (e.g. default('}}')) from prematurely terminating an expression block.
Changes:
- Replaced
_EXPR_PATTERN.sub(...)multi-expression interpolation with_interpolate_expressions(...)that finds closing}}outside string literals. - Added regression tests covering literal
}}and literal{{inside quoted filter arguments in multi-expression templates.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/expressions.py |
Implements quote-aware multi-expression interpolation to avoid truncating blocks when }} appears inside quoted arguments. |
tests/test_workflows.py |
Adds regression tests for }} / {{ literals inside quoted filter args across multi-expression templates. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Low
Comment on lines
+225
to
+229
| if close == -1: | ||
| # No closing delimiter: leave the unterminated ``{{`` verbatim, the | ||
| # same way the regex leaves an unmatched opener untouched. | ||
| out.append(template[start:]) | ||
| break |
mnriem
requested changes
Jul 2, 2026
mnriem
left a comment
Collaborator
There was a problem hiding this comment.
Please address Copilot feedback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #3306
what
evaluate_expression's multi-expression interpolation path still used the regexthe non-greedy
(.+?)}}body stops at the first}}regardless of quoting, so a multi-expression template with a literal}}inside a quoted filter argument captured a truncated block body and raisedValueErrorfrom the filter parser.{{ inputs.name }}: {{ inputs.missing | default('}}') }}raised instead of returningBob: }}.the single-expression fast path was already hardened for exactly this in #3208 / #3228 (
_is_single_expressionscans for a}}outside string literals). this brings the interpolation path to the same handling.how
replaced
_EXPR_PATTERN.subwith_interpolate_expressions, which walks the template and, for each{{ ... }}block, finds the closing}}outside string literals - reusing the same quote-scan_is_single_expressionalready uses. a literal}}in a plain resolved value (not an expression) passes through unchanged, and an unterminated{{is left verbatim, matching the old regex behavior.tests
test_multi_expression_with_literal_close_brace_in_argument-}}in the second block and in the first block. fails on the current code withValueError, passes with the fix.test_multi_expression_with_literal_open_brace_in_argument-{{guard.TestExpressions(36) and fulltests/test_workflows.py(363) pass.verified the regression test fails on pre-fix code by reverting only the source change and re-running (raised
ValueErroronexpressions.py:480), then confirmed it passes with the fix restored.