@@ -38,6 +38,7 @@ protected function setUp(): void
38
38
'obj ' => new FooObject (),
39
39
'arr ' => ['obj ' => new FooObject ()],
40
40
'child_obj ' => new ChildClass (),
41
+ 'some_array ' => [5 , 6 , 7 , new FooObject ()],
41
42
];
42
43
43
44
self ::$ templates = [
@@ -184,10 +185,10 @@ public function testSandboxUnallowedProperty()
184
185
*/
185
186
public function testSandboxUnallowedToString ($ template )
186
187
{
187
- $ twig = $ this ->getEnvironment (true , [], ['index ' => $ template ], [], ['upper ' ], ['Twig\Tests\Extension\FooObject ' => 'getAnotherFooObject ' ], [], ['random ' ]);
188
+ $ twig = $ this ->getEnvironment (true , [], ['index ' => $ template ], [], ['upper ' , ' join ' , ' replace ' ], ['Twig\Tests\Extension\FooObject ' => 'getAnotherFooObject ' ], [], ['random ' ]);
188
189
try {
189
190
$ twig ->load ('index ' )->render (self ::$ params );
190
- $ this ->fail ('Sandbox throws a SecurityError exception if an unallowed method ( __toString()) is called in the template ' );
191
+ $ this ->fail ('Sandbox throws a SecurityError exception if an unallowed method " __toString()" method is called in the template ' );
191
192
} catch (SecurityNotAllowedMethodError $ e ) {
192
193
$ this ->assertEquals ('Twig\Tests\Extension\FooObject ' , $ e ->getClassName (), 'Exception should be raised on the "Twig\Tests\Extension\FooObject" class ' );
193
194
$ this ->assertEquals ('__tostring ' , $ e ->getMethodName (), 'Exception should be raised on the "__toString" method ' );
@@ -210,6 +211,16 @@ public function getSandboxUnallowedToStringTests()
210
211
'object_chain_and_function ' => ['{{ random(obj.anotherFooObject) }} ' ],
211
212
'concat ' => ['{{ obj ~ "" }} ' ],
212
213
'concat_again ' => ['{{ "" ~ obj }} ' ],
214
+ 'object_in_arguments ' => ['{{ "__toString"|replace({"__toString": obj}) }} ' ],
215
+ 'object_in_array ' => ['{{ [12, "foo", obj]|join(", ") }} ' ],
216
+ 'object_in_array_var ' => ['{{ some_array|join(", ") }} ' ],
217
+ 'object_in_array_nested ' => ['{{ [12, "foo", [12, "foo", obj]]|join(", ") }} ' ],
218
+ 'object_in_array_var_nested ' => ['{{ [12, "foo", some_array]|join(", ") }} ' ],
219
+ 'object_in_array_dynamic_key ' => ['{{ {(obj): "foo"}|join(", ") }} ' ],
220
+ 'object_in_array_dynamic_key_nested ' => ['{{ {"foo": { (obj): "foo" }}|join(", ") }} ' ],
221
+ 'context ' => ['{{ _context|join(", ") }} ' ],
222
+ 'spread_array_operator ' => ['{{ [1, 2, ...[5, 6, 7, obj]]|join(",") }} ' ],
223
+ 'spread_array_operator_var ' => ['{{ [1, 2, ...some_array]|join(",") }} ' ],
213
224
];
214
225
}
215
226
0 commit comments