mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-03 05:56:43 +00:00
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:
+4
-5
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user