Merge branch '1.x' into 2.x

* 1.x:
  Fix a regression when not using a space before an operator
This commit is contained in:
Fabien Potencier
2020-07-06 15:35:12 +02:00
3 changed files with 10 additions and 5 deletions
+4 -5
View File
@@ -466,16 +466,15 @@ class Lexer
$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(__DIR__), 'object' => new \stdClass(), 'resource' => opendir(__DIR__), 'safe' => new \Twig\Markup('foo', 'UTF-8')]
--EXPECT--
@@ -124,3 +125,4 @@ OK
OK
OK
OK
OK