Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Nov 6, 2024
1 parent 94612e7 commit 5b580ec
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ public static function getAttribute(Environment $env, Source $source, $object, $
if (/* Template::METHOD_CALL */ 'method' !== $type) {
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;

if ($sandboxed && $object instanceof \ArrayAccess && !\in_array($object::class, self::ARRAY_LIKE_CLASSES, true)) {
if ($sandboxed && $object instanceof \ArrayAccess && !\in_array(get_class($object), self::ARRAY_LIKE_CLASSES, true)) {
try {
$env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $arrayItem, $lineno, $source);
} catch (SecurityNotAllowedPropertyError $propertyNotAllowedError) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/GetAttrExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function compile(Compiler $compiler): void
->raw(') || ')
->raw($var)
->raw(' instanceof ArrayAccess && in_array(')
->raw($var.'::class')
->raw('get_class('.$var.')')
->raw(', CoreExtension::ARRAY_LIKE_CLASSES, true) ? (')
->raw($var)
->raw('[')
Expand Down
4 changes: 2 additions & 2 deletions tests/Extension/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function testSandboxedInclude()
'index' => '{{ include("included", sandboxed=true) }}',
'included' => '{{ "included"|e }}',
]));
$policy = new SecurityPolicy(allowedFunctions: ['include']);
$policy = new SecurityPolicy([], [], [], [], ['include']);
$sandbox = new SandboxExtension($policy, false);
$twig->addExtension($sandbox);

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

Expand Down

0 comments on commit 5b580ec

Please sign in to comment.