Skip to content

Commit 5b580ec

Browse files
committed
Fix code
1 parent 94612e7 commit 5b580ec

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/Extension/CoreExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ public static function getAttribute(Environment $env, Source $source, $object, $
15711571
if (/* Template::METHOD_CALL */ 'method' !== $type) {
15721572
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;
15731573

1574-
if ($sandboxed && $object instanceof \ArrayAccess && !\in_array($object::class, self::ARRAY_LIKE_CLASSES, true)) {
1574+
if ($sandboxed && $object instanceof \ArrayAccess && !\in_array(get_class($object), self::ARRAY_LIKE_CLASSES, true)) {
15751575
try {
15761576
$env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $arrayItem, $lineno, $source);
15771577
} catch (SecurityNotAllowedPropertyError $propertyNotAllowedError) {

src/Node/Expression/GetAttrExpression.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function compile(Compiler $compiler): void
6767
->raw(') || ')
6868
->raw($var)
6969
->raw(' instanceof ArrayAccess && in_array(')
70-
->raw($var.'::class')
70+
->raw('get_class('.$var.')')
7171
->raw(', CoreExtension::ARRAY_LIKE_CLASSES, true) ? (')
7272
->raw($var)
7373
->raw('[')

tests/Extension/CoreTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function testSandboxedInclude()
325325
'index' => '{{ include("included", sandboxed=true) }}',
326326
'included' => '{{ "included"|e }}',
327327
]));
328-
$policy = new SecurityPolicy(allowedFunctions: ['include']);
328+
$policy = new SecurityPolicy([], [], [], [], ['include']);
329329
$sandbox = new SandboxExtension($policy, false);
330330
$twig->addExtension($sandbox);
331331

@@ -340,7 +340,7 @@ public function testSandboxedIncludeWithPreloadedTemplate()
340340
'index' => '{{ include("included", sandboxed=true) }}',
341341
'included' => '{{ "included"|e }}',
342342
]));
343-
$policy = new SecurityPolicy(allowedFunctions: ['include']);
343+
$policy = new SecurityPolicy([], [], [], [], ['include']);
344344
$sandbox = new SandboxExtension($policy, false);
345345
$twig->addExtension($sandbox);
346346

0 commit comments

Comments
 (0)