@@ -42,6 +42,7 @@ protected function setUp(): void
42
42
'obj ' => new FooObject (),
43
43
'arr ' => ['obj ' => new FooObject ()],
44
44
'child_obj ' => new ChildClass (),
45
+ 'some_array ' => [5 , 6 , 7 , new FooObject ()],
45
46
];
46
47
47
48
self ::$ templates = [
@@ -246,10 +247,10 @@ public function testSandboxUnallowedProperty()
246
247
*/
247
248
public function testSandboxUnallowedToString ($ template )
248
249
{
249
- $ twig = $ this ->getEnvironment (true , [], ['index ' => $ template ], [], ['upper ' ], ['Twig\Tests\Extension\FooObject ' => 'getAnotherFooObject ' ], [], ['random ' ]);
250
+ $ twig = $ this ->getEnvironment (true , [], ['index ' => $ template ], [], ['upper ' , ' join ' , ' replace ' ], ['Twig\Tests\Extension\FooObject ' => 'getAnotherFooObject ' ], [], ['random ' ]);
250
251
try {
251
252
$ twig ->load ('index ' )->render (self ::$ params );
252
- $ this ->fail ('Sandbox throws a SecurityError exception if an unallowed method ( __toString()) is called in the template ' );
253
+ $ this ->fail ('Sandbox throws a SecurityError exception if an unallowed method " __toString()" method is called in the template ' );
253
254
} catch (SecurityNotAllowedMethodError $ e ) {
254
255
$ this ->assertEquals ('Twig\Tests\Extension\FooObject ' , $ e ->getClassName (), 'Exception should be raised on the "Twig\Tests\Extension\FooObject" class ' );
255
256
$ this ->assertEquals ('__tostring ' , $ e ->getMethodName (), 'Exception should be raised on the "__toString" method ' );
@@ -272,6 +273,16 @@ public static function getSandboxUnallowedToStringTests()
272
273
'object_chain_and_function ' => ['{{ random(obj.anotherFooObject) }} ' ],
273
274
'concat ' => ['{{ obj ~ "" }} ' ],
274
275
'concat_again ' => ['{{ "" ~ obj }} ' ],
276
+ 'object_in_arguments ' => ['{{ "__toString"|replace({"__toString": obj}) }} ' ],
277
+ 'object_in_array ' => ['{{ [12, "foo", obj]|join(", ") }} ' ],
278
+ 'object_in_array_var ' => ['{{ some_array|join(", ") }} ' ],
279
+ 'object_in_array_nested ' => ['{{ [12, "foo", [12, "foo", obj]]|join(", ") }} ' ],
280
+ 'object_in_array_var_nested ' => ['{{ [12, "foo", some_array]|join(", ") }} ' ],
281
+ 'object_in_array_dynamic_key ' => ['{{ {(obj): "foo"}|join(", ") }} ' ],
282
+ 'object_in_array_dynamic_key_nested ' => ['{{ {"foo": { (obj): "foo" }}|join(", ") }} ' ],
283
+ 'context ' => ['{{ _context|join(", ") }} ' ],
284
+ 'spread_array_operator ' => ['{{ [1, 2, ...[5, 6, 7, obj]]|join(",") }} ' ],
285
+ 'spread_array_operator_var ' => ['{{ [1, 2, ...some_array]|join(",") }} ' ],
275
286
];
276
287
}
277
288
0 commit comments