Fix a regression when not using a space before an operator

This commit is contained in:
Fabien Potencier
2020-07-06 14:36:10 +02:00
parent aa182ff7c1
commit 841906b110
3 changed files with 10 additions and 5 deletions
+4 -5
View File
@@ -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 = '(?<![\.\|])'.$r;
}
// an operator with a space can be any amount of whitespaces
+4
View File
@@ -3,8 +3,12 @@ not
--TEMPLATE--
{{ (not false) ? 'OK' : 'KO' }}
{{ not false ? 'OK' : 'KO' }}
{{ (not false)?'OK':'KO' }}
{{ not false?'OK':'KO' }}
--DATA--
return []
--EXPECT--
OK
OK
OK
OK
+2
View File
@@ -61,6 +61,7 @@ Twig supports the in operator
{{ 'value'|not in ['not value'] ? 'OK' : 'KO' }}
{{ foo.not not in ['not'] ? 'KO' : 'OK' }}
{{ 'value'|not not in ['not value'] ? 'KO' : 'OK' }}
{{ 'value'not in['not value'] ? 'OK' : 'KO' }}
--DATA--
return ['bar' => '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