Skip to content

Commit 3b2068a

Browse files
authored
Closes #388 (#398)
1 parent b50247f commit 3b2068a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Node/GetAttrNode.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace TwigBridge\Node;
99

10+
use ArrayAccess;
1011
use Twig\Compiler;
1112
use Twig\Environment;
1213
use Twig\Error\RuntimeError;
@@ -129,7 +130,12 @@ public static function attribute(
129130
$sandboxed = false,
130131
int $lineno = -1
131132
) {
132-
if (Template::METHOD_CALL !== $type and is_a($object, 'Illuminate\Database\Eloquent\Model')) {
133+
// Twig doesn't support sandboxing on objects that implement ArrayAccess
134+
// https://github.com/twigphp/Twig/issues/106#issuecomment-583737
135+
// https://github.com/twigphp/Twig/pull/1863
136+
//
137+
// https://github.com/twigphp/Twig/issues/2878
138+
if (Template::METHOD_CALL !== $type and $object instanceof ArrayAccess) {
133139
// We can't easily find out if an attribute actually exists, so return true
134140
if ($isDefinedTest) {
135141
return true;
@@ -139,7 +145,7 @@ public static function attribute(
139145
$env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $item);
140146
}
141147

142-
// Call the attribute, the Model object does the rest of the magic
148+
// Call the attribute, the object does the rest of the magic
143149
return $object->$item;
144150
}
145151

0 commit comments

Comments
 (0)