From 5663351a49f5ad49778dd9a4cbf30a6d7b29f429 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 23 Feb 2020 09:40:57 +0100 Subject: [PATCH] Fix ambiguous syntax parsing --- src/Lexer.php | 3 ++- tests/Fixtures/expressions/not.test | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/expressions/not.test diff --git a/src/Lexer.php b/src/Lexer.php index 2de5fc79a..b93790c61 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -506,8 +506,9 @@ class Lexer implements \Twig_LexerInterface } // an operator that begins with a character must have a space before + // or a parenthesis if (ctype_alpha($operator[0])) { - $r = '(?<=\s)'.$r; + $r = '(?<=[\s(])'.$r; } // an operator with a space can be any amount of whitespaces diff --git a/tests/Fixtures/expressions/not.test b/tests/Fixtures/expressions/not.test new file mode 100644 index 000000000..40914a3e1 --- /dev/null +++ b/tests/Fixtures/expressions/not.test @@ -0,0 +1,10 @@ +--TEST-- +not +--TEMPLATE-- +{{ (not false) ? 'OK' : 'KO' }} +{{ not false ? 'OK' : 'KO' }} +--DATA-- +return [] +--EXPECT-- +OK +OK