mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-11 06:15:43 +00:00
Reject the spread operator outside sequences, mappings, and call arguments
This commit is contained in:
@@ -126,6 +126,41 @@ class ExpressionParserTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getMisplacedSpreadTests
|
||||
*/
|
||||
#[DataProvider('getMisplacedSpreadTests')]
|
||||
public function testMisplacedSpreadIsASyntaxError(string $template): void
|
||||
{
|
||||
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
|
||||
$parser = new Parser($env);
|
||||
|
||||
$this->expectException(SyntaxError::class);
|
||||
$this->expectExceptionMessage('The spread operator can only be used on sequence elements, mapping elements, and call arguments in "index" at line 1.');
|
||||
$parser->parse($env->tokenize(new Source($template, 'index')));
|
||||
}
|
||||
|
||||
public static function getMisplacedSpreadTests()
|
||||
{
|
||||
return [
|
||||
['{{ ...foo }}'],
|
||||
['{{ (...foo) }}'],
|
||||
['{{ -...foo }}'],
|
||||
['{{ 1 + ...foo }}'],
|
||||
['{% set bar = ...foo %}'],
|
||||
['{% do ...foo %}'],
|
||||
['{% with ...foo %}{% endwith %}'],
|
||||
['{{ (bar => ...foo)(1) }}'],
|
||||
['{{ [(...foo)] }}'],
|
||||
['{{ [1, -...foo] }}'],
|
||||
['{{ {a: ...foo} }}'],
|
||||
['{{ {(...foo): 1} }}'],
|
||||
['{{ bar(-...foo) }}'],
|
||||
['{{ bar(a: ...foo) }}'],
|
||||
['{{ bar(a = ...foo) }}'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getTestsForSequence()
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user