From 841906b1103599291a72044fcde3aafd9f2272f8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 6 Jul 2020 14:36:10 +0200 Subject: [PATCH] Fix a regression when not using a space before an operator --- src/Lexer.php | 9 ++++----- tests/Fixtures/expressions/not.test | 4 ++++ tests/Fixtures/tests/in.test | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Lexer.php b/src/Lexer.php index b93790c61..6fb8dd062 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -499,16 +499,15 @@ class Lexer implements \Twig_LexerInterface $regex = []; foreach ($operators as $operator => $length) { // an operator that ends with a character must be followed by - // a whitespace or a parenthesis + // a whitespace, a parenthesis, an opening map [ or sequence { $r = preg_quote($operator, '/'); if (ctype_alpha($operator[$length - 1])) { - $r .= '(?=[\s()])'; + $r .= '(?=[\s()\[{])'; } - // an operator that begins with a character must have a space before - // or a parenthesis + // an operator that begins with a character must not have a dot or pipe before if (ctype_alpha($operator[0])) { - $r = '(?<=[\s(])'.$r; + $r = '(? 'bar', 'foo' => ['bar' => 'bar', 'not' => 'not'], 'dir_object' => new \SplFileInfo(dirname(__FILE__)), 'object' => new \stdClass(), 'resource' => opendir(dirname(__FILE__)), 'safe' => new \Twig\Markup('foo', 'UTF-8')] --EXPECT-- @@ -124,3 +125,4 @@ OK OK OK OK +OK