mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 03:57:21 +00:00
Fix ambiguous syntax parsing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 1.42.6 (2020-XX-XX)
|
||||
|
||||
* n/a
|
||||
* Fix ambiguous syntax parsing
|
||||
|
||||
# 1.42.5 (2020-02-11)
|
||||
|
||||
|
||||
+7
-3
@@ -500,10 +500,14 @@ class Lexer implements \Twig_LexerInterface
|
||||
foreach ($operators as $operator => $length) {
|
||||
// an operator that ends with a character must be followed by
|
||||
// a whitespace or a parenthesis
|
||||
$r = preg_quote($operator, '/');
|
||||
if (ctype_alpha($operator[$length - 1])) {
|
||||
$r = preg_quote($operator, '/').'(?=[\s()])';
|
||||
} else {
|
||||
$r = preg_quote($operator, '/');
|
||||
$r .= '(?=[\s()])';
|
||||
}
|
||||
|
||||
// an operator that begins with a character must have a space before
|
||||
if (ctype_alpha($operator[0])) {
|
||||
$r = '(?<=\s)'.$r;
|
||||
}
|
||||
|
||||
// an operator with a space can be any amount of whitespaces
|
||||
|
||||
@@ -57,8 +57,13 @@ Twig supports the in operator
|
||||
|
||||
{{ safe in ['foo', 'bar'] ? 'OK' : 'KO' }}
|
||||
{{ 'fo' in safe ? 'OK' : 'KO' }}
|
||||
|
||||
{{ foo.not in ['not'] ? 'OK' : 'KO' }}
|
||||
{{ 'value'|not in ['not value'] ? 'OK' : 'KO' }}
|
||||
{{ foo.not not in ['not'] ? 'KO' : 'OK' }}
|
||||
{{ 'value'|not not in ['not value'] ? 'KO' : 'OK' }}
|
||||
--DATA--
|
||||
return ['bar' => 'bar', 'foo' => ['bar' => 'bar'], 'dir_object' => new \SplFileInfo(dirname(__FILE__)), 'object' => new \stdClass(), 'resource' => opendir(dirname(__FILE__)), 'safe' => new \Twig\Markup('foo', 'UTF-8')]
|
||||
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--
|
||||
OK
|
||||
OK
|
||||
@@ -116,3 +121,8 @@ OK
|
||||
|
||||
OK
|
||||
OK
|
||||
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
OK
|
||||
|
||||
@@ -164,6 +164,7 @@ class TwigTestExtension extends AbstractExtension
|
||||
new TwigFilter('magic_call_array', ['Twig\Tests\TwigTestExtension', 'magicStaticCall']),
|
||||
new TwigFilter('*_path', [$this, 'dynamic_path']),
|
||||
new TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']),
|
||||
new TwigFilter('not', [$this, 'notFilter']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -188,6 +189,11 @@ class TwigTestExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
public function notFilter($value)
|
||||
{
|
||||
return 'not '.$value;
|
||||
}
|
||||
|
||||
public function §Filter($value)
|
||||
{
|
||||
return "§{$value}§";
|
||||
|
||||
Reference in New Issue
Block a user