Skip to content

[TwigComponent] Fix twig:blockquote is not a block - #3762

Open
smnandre wants to merge 1 commit into
symfony:3.xfrom
smnandre:fix/block-quote-bug
Open

[TwigComponent] Fix twig:blockquote is not a block#3762
smnandre wants to merge 1 commit into
symfony:3.xfrom
smnandre:fix/block-quote-bug

Conversation

@smnandre

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

A component whose name starts with block breaks the block it sits in.

Reproducer

<twig:Card>
    <twig:block name="footer">
        <twig:blockquote cite="Matt">He ho!</twig:blockquote>
    </twig:block>
</twig:Card>
Twig\Error\SyntaxError: Expected closing tag "</twig:Card>" not found at line 5.

The error points at Card, which is correctly closed, and at the last line of the
template. Nothing mentions blockquote, so there is little to go on.

Same failure with <twig:blockquote />, <twig:block-title />, <twig:blocked />, and
inside a traditional {% block %} … {% endblock %}.

Not affected: <twig:Blockquote /> (the comparison is case-sensitive), and any of these
outside a block.

Cause

TwigPreLexer::consumeUntilEndBlock() tracks block nesting with a fixed-length prefix
comparison:

if (!$inComment && '<twig:block' === substr($this->input, $this->position, 11)) {
    ++$depth;
}

'<twig:block' is also the first 11 characters of <twig:blockquote, so the depth is
incremented for a component that is not a block. It is never decremented back: the
closing comparison is '</twig:block>', which ends with > and therefore does not
match </twig:blockquote>. The enclosing <twig:block> never terminates, scanning runs
to the end of the template, and the outer component is reported as unclosed.

Fix

Anchor the match and require that block is not followed by another component-name
character, using the same character class as consumeComponentName():

if (!$inComment && preg_match('/\G<twig:block(?![A-Za-z0-9_:@\-.])/', $this->input, $matches, 0, $this->position)) {
    ++$depth;
}

The closing comparison needs no change.

@smnandre smnandre added the Bug Bug Fix label Aug 10, 2026
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Bug Fix Status: Reviewed Has been reviewed by a maintainer TwigComponent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants