Opened 18 minutes ago
#37530 assigned Bug
The multiline `endcomment` closes the block early, leaving the final, single-line `endcomment` outside it.
| Reported by: | Cleisson | Owned by: | Cleisson |
|---|---|---|---|
| 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
The Django 6.2 release notes say that setting allow_multiline_tags=False restores the previous template parsing behavior. However, the template below compiles on Django 6.1 but fails on 6.2 even with this setting.
To reproduce on the Django 6.2 development version:
from django.template import Context, Engine source = "{% comment %}x{%\nendcomment %}y{% endcomment %}z" print(Engine(allow_multiline_tags=False).from_string(source).render(Context()))
Expected output: z. The first endcomment has its {% and %} on separate lines, so it should remain comment text. The final, single-line endcomment should close the block. On Django 6.1.3, the same template prints z using Engine() without the new option.
On main at c67d872765e05ebd009fadf7de8d834b01bae9e4 (6.2 alpha 0), it raises:
TemplateSyntaxError: Invalid block tag on line 2: 'endcomment'. Did you forget to register or load this tag?
The multiline endcomment closes the block early, leaving the final, single-line endcomment outside it. Both versions were tested with Python 3.14.6.
Lexer._tag_re_split() uses separate patterns to match closing tags inside comment and verbatim blocks. These patterns still match across newlines when allow_multiline_tags=False. This also affects named and unnamed verbatim blocks: they end early instead of rendering the multiline lookalike as literal text.
With allow_multiline_tags=True, a multiline closing tag on its own ends each block as expected. #37518 concerns a missing space between endverbatim and the block name in the default mode.
AI disclosure: OpenAI GPT-6.2 (Astra and Sol, via OpenCode) was used to investigate and reproduce the bug.