@@ -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 = [
@@ -261,10 +262,10 @@ public function testSandboxUnallowedProperty()
261
262
*/
262
263
public function testSandboxUnallowedToString ($ template )
263
264
{
264
- $ twig = $ this ->getEnvironment (true , [], ['index ' => $ template ], [], ['upper ' ], ['Twig\Tests\Extension\FooObject ' => 'getAnotherFooObject ' ], [], ['random ' ]);
265
+ $ twig = $ this ->getEnvironment (true , [], ['index ' => $ template ], [], ['upper ' , ' join ' , ' replace ' ], ['Twig\Tests\Extension\FooObject ' => 'getAnotherFooObject ' ], [], ['random ' ]);
265
266
try {
266
267
$ twig ->load ('index ' )->render (self ::$ params );
267
- $ this ->fail ('Sandbox throws a SecurityError exception if an unallowed method ( __toString()) is called in the template ' );
268
+ $ this ->fail ('Sandbox throws a SecurityError exception if an unallowed method " __toString()" method is called in the template ' );
268
269
} catch (SecurityNotAllowedMethodError $ e ) {
269
270
$ this ->assertEquals ('Twig\Tests\Extension\FooObject ' , $ e ->getClassName (), 'Exception should be raised on the "Twig\Tests\Extension\FooObject" class ' );
270
271
$ this ->assertEquals ('__tostring ' , $ e ->getMethodName (), 'Exception should be raised on the "__toString" method ' );
@@ -287,6 +288,16 @@ public static function getSandboxUnallowedToStringTests()
287
288
'object_chain_and_function ' => ['{{ random(obj.anotherFooObject) }} ' ],
288
289
'concat ' => ['{{ obj ~ "" }} ' ],
289
290
'concat_again ' => ['{{ "" ~ obj }} ' ],
291
+ 'object_in_arguments ' => ['{{ "__toString"|replace({"__toString": obj}) }} ' ],
292
+ 'object_in_array ' => ['{{ [12, "foo", obj]|join(", ") }} ' ],
293
+ 'object_in_array_var ' => ['{{ some_array|join(", ") }} ' ],
294
+ 'object_in_array_nested ' => ['{{ [12, "foo", [12, "foo", obj]]|join(", ") }} ' ],
295
+ 'object_in_array_var_nested ' => ['{{ [12, "foo", some_array]|join(", ") }} ' ],
296
+ 'object_in_array_dynamic_key ' => ['{{ {(obj): "foo"}|join(", ") }} ' ],
297
+ 'object_in_array_dynamic_key_nested ' => ['{{ {"foo": { (obj): "foo" }}|join(", ") }} ' ],
298
+ 'context ' => ['{{ _context|join(", ") }} ' ],
299
+ 'spread_array_operator ' => ['{{ [1, 2, ...[5, 6, 7, obj]]|join(",") }} ' ],
300
+ 'spread_array_operator_var ' => ['{{ [1, 2, ...some_array]|join(",") }} ' ],
290
301
];
291
302
}
292
303
0 commit comments