Craft CMS defines a literal filter, which conflicts with the new literal operator introduced in Twig 3.21 via #4543.
For example, the following template will trigger the error: Unexpected token "operator" of value "literal" ("name" expected).
Lexer::getOperatorRegex() is defensive against filters being confused for operators here:
|
// an operator that begins with a character must not have a dot or pipe before |
|
if (ctype_alpha($expressionParser[0])) { |
|
$r = '(?<![\.\|])'.$r; |
|
} |
However the lookbehind doesn’t account for filters that have spaces around them, which is pretty commonplace.
Suggested fix
Changing that lookbehind code to the following fixes the problem:
$r = '(?<![\.\|]\s|.[\.\|])'.$r;
(It’s not possible to have variable-length lookbehinds, so I believe this is the only way to do it, with that . and all, rather than just (?<![\.\|]\s?).)
Craft CMS defines a
literalfilter, which conflicts with the newliteraloperator introduced in Twig 3.21 via #4543.For example, the following template will trigger the error:
Unexpected token "operator" of value "literal" ("name" expected).{{ 'foo' | literal }}Lexer::getOperatorRegex()is defensive against filters being confused for operators here:Twig/src/Lexer.php
Lines 545 to 548 in a64dc5d
However the lookbehind doesn’t account for filters that have spaces around them, which is pretty commonplace.
Suggested fix
Changing that lookbehind code to the following fixes the problem:
(It’s not possible to have variable-length lookbehinds, so I believe this is the only way to do it, with that
.and all, rather than just(?<![\.\|]\s?).)