-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
literal filter/operator conflict #4767
Copy link
Copy link
Description
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).
{{ 'foo' | literal }}Lexer::getOperatorRegex() is defensive against filters being confused for operators here:
Lines 545 to 548 in a64dc5d
| // 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?).)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels