mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
Fix two-word tests precedence over one-word tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# 3.12.0 (2024-XX-XX)
|
# 3.12.0 (2024-XX-XX)
|
||||||
|
|
||||||
|
* Fix precedence of two-word tests when the first word is a valid test
|
||||||
* Deprecate the `spaceless` filter
|
* Deprecate the `spaceless` filter
|
||||||
* Deprecate some internal methods from `Parser`: `getBlockStack()`, `hasBlock()`, `getBlock()`, `hasMacro()`, `hasTraits()`, `getParent()`
|
* Deprecate some internal methods from `Parser`: `getBlockStack()`, `hasBlock()`, `getBlock()`, `hasMacro()`, `hasTraits()`, `getParent()`
|
||||||
* Deprecate passing `null` to `Twig\Parser::setParent()`
|
* Deprecate passing `null` to `Twig\Parser::setParent()`
|
||||||
|
|||||||
@@ -750,15 +750,15 @@ class ExpressionParser
|
|||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||||
|
|
||||||
if (!$test = $this->env->getTest($name)) {
|
if ($stream->test(Token::NAME_TYPE)) {
|
||||||
if ($stream->test(Token::NAME_TYPE)) {
|
// try 2-words tests
|
||||||
// try 2-words tests
|
$name = $name.' '.$this->parser->getCurrentToken()->getValue();
|
||||||
$name = $name.' '.$this->parser->getCurrentToken()->getValue();
|
|
||||||
|
|
||||||
if ($test = $this->env->getTest($name)) {
|
if ($test = $this->env->getTest($name)) {
|
||||||
$stream->next();
|
$stream->next();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$test = $this->env->getTest($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$test) {
|
if (!$test) {
|
||||||
|
|||||||
@@ -573,6 +573,17 @@ class ExpressionParserTest extends TestCase
|
|||||||
$this->doesNotPerformAssertions();
|
$this->doesNotPerformAssertions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTwoWordTestPrecedence()
|
||||||
|
{
|
||||||
|
// a "empty element" test must have precedence over "empty"
|
||||||
|
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
|
||||||
|
$env->addTest(new TwigTest('empty element', 'foo'));
|
||||||
|
$parser = new Parser($env);
|
||||||
|
|
||||||
|
$parser->parse($env->tokenize(new Source('{{ 1 is empty element }}', 'index')));
|
||||||
|
$this->doesNotPerformAssertions();
|
||||||
|
}
|
||||||
|
|
||||||
private function createNameExpression(string $name, array $attributes)
|
private function createNameExpression(string $name, array $attributes)
|
||||||
{
|
{
|
||||||
$expression = new NameExpression($name, 1);
|
$expression = new NameExpression($name, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user