Opened 9 minutes ago
#37518 assigned Bug
Named verbatim blocks mistake literal text for the closing tag
| Reported by: | Mariano Ignacio Baragiola | Owned by: | Mariano Ignacio Baragiola |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
On Django main (03b95b8fba), run:
from django.template import Context, Engine source = ( "{% verbatim note %}before {% endverbatimnote %} after" "{% endverbatim note %}" ) print(Engine().from_string(source).render(Context()))
Expected: before {% endverbatimnote %} after
Actual: TemplateSyntaxError: Invalid block tag on line 1: 'endverbatimnote', expected 'endverbatim'.
The closing-tag matcher added in #35899 accepts zero whitespace between endverbatim and the block name. Requiring at least one whitespace character keeps the literal text inside the block. A local patch and regression test are ready.
AI disclosure: OpenAI Codex assisted with diagnosis, the patch and regression test, and drafting this report.