fix: allow % and } in {%p %}/{%tr %}/{%tc %}/{%r %} expressions#645
Open
Noethix55555 wants to merge 1 commit into
Open
fix: allow % and } in {%p %}/{%tr %}/{%tc %}/{%r %} expressions#645Noethix55555 wants to merge 1 commit into
Noethix55555 wants to merge 1 commit into
Conversation
patch_xml matched the expression body of these directive tags with
[^}%]*, which stops at the first % or }. Tags whose expression contains a
modulo (if i % 2 == 0) or a literal brace (set d = {"x":1}) were not
stripped of their surrounding <w:p>/<w:tr>/<w:tc>/<w:r> wrapper, so the
literal {%p ...%} reached Jinja and raised TemplateSyntaxError:
Encountered unknown tag 'p'.
Match up to the closing %} or }} instead of excluding the characters.
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 #644.
patch_xmlmatched the expression body of these directive tags with[^}%]*, which stops at the first%or}. Tags whose expression contains a modulo (if i % 2 == 0) or a literal brace (set d = {"x":1}) were not stripped of their surrounding<w:p>/<w:tr>/<w:tc>/<w:r>wrapper, so the literal{%p ...%}reached Jinja and raisedTemplateSyntaxError: Encountered unknown tag 'p'.The fix matches up to the closing
%}/}}instead of excluding those characters:Verified with a real render: a template using
{%p if i % 2 == 0 %}raisesTemplateSyntaxErroron the current code and renders correctly with the fix. The representative existing fixture tests (dynamic_table, nested_for, vertical_merge, horizontal_merge, less_cells_after_loop, comments, escape, merge_paragraph, richtext, order and others) still pass.CI runs flake8 only and the existing tests are binary
.docxfixtures with no assertions, so I did not add a fixture; the reproduction above is in the linked issue. Happy to add a fixture-based test if you prefer.