Repository navigation
fix(templates): read every continuation of a comment holding template tags - #281
Merged
Merged
Conversation
…t ending in HTML data The reading ended a comment holding template tags at its first tag. Those tags may also render nothing, and the comment, left open, then hides what follows. A text ending in such a comment therefore does not end in HTML data, and an include of a name several files have, one of which ends so, is refused (#273).
…tinuation of a comment resumes Since #272, the reading ended a comment holding template tags at its first tag. In the rendered page, the comment may also end at a later tag, or run to its close when its tags render nothing, and the markup after that point is read from HTML data. In <!--{% if debug %}{% endif %}<a title="--><{{ name }}">, the comment runs to the "-->" in the title, and the variable after it names a tag (#278). The reading resumed after the first tag is kept, and it must be in HTML data right after each later tag of the comment and right after its close, where the other readings resume; where it is not, the text is refused. An inserted markup anywhere inside such a comment is refused. The reading stays linear. The points of resumption come in two sequences that never go back, each held in a queue, and inserted markups are looked up by position. On 1.7 million generated texts, it never accepts a text that a reading of every continuation refuses.
Merged
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.
Summary
Closes #278.
Since #272, the reading ended a comment holding template tags at its first tag, and read what follows as markup. In the rendered page, the comment may also:
The markup after that point is then read from HTML data. In
<!--{% if debug %}{% endif %}<a title="--><{{ name }}">x</a>, the comment runs to the-->in the title. The variable after it names a tag: Django 5.1.15 renders<!--<a title="--><img src=x onerror=...>, and Chrome runs the handler. Nothing was reported, where 0.23.0 reported it. The regression is in no release.Rule
Why the cost is linear
The reading only moves forward, and every part of the text is looked at once:
main<repeated<!--{% if x %}repeated<p>x</p>repeated--><!--{% if x %}<arepeatedfix(templates): count a comment holding template tags left open as not ending in HTML datafix(templates): require the reading in HTML data wherever another continuation of a comment resumesdocs: state how a comment holding template tags is readdocs/usage.md, the module's docstringResults
Bench of generated texts. 1,708,598 texts were checked, every text of up to five pieces and 200,000 random ones. The reading was compared with
main's, and with a reference reading every continuation, which is quadratic:mainrefuses;mainaccepted are refused, rightly;<!--{% if %}<a title="--><!--.Corpus. On the local corpus, 614 templates are established before and after, and none changes. The remote battery could not be reached.
Reproductions.
Tests
The new file
tests/test_template_comment_continuations.pyholds 7 tests, 15 cases. No existing test changes.Before the fix.
main: the left-open test fails, and so do the 5 tests of the second commit.main.Mutations. Each of these makes at least one test fail:
Verification
Python 3.12, on
mainat0da4cc8:ruff check .andmypy: clean on each commit;This change and the fix of #279 touch different parts of
taint/templates.py. Applied in either order, they give the same tree, on whichruffandmypyare clean, the unit suite passes (2,646) and the regression too (19 of 19).