Skip to content

Commit

Permalink
Closes #388 (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytestream authored Jun 22, 2020
1 parent b50247f commit 3b2068a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Node/GetAttrNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace TwigBridge\Node;

use ArrayAccess;
use Twig\Compiler;
use Twig\Environment;
use Twig\Error\RuntimeError;
Expand Down Expand Up @@ -129,7 +130,12 @@ public static function attribute(
$sandboxed = false,
int $lineno = -1
) {
if (Template::METHOD_CALL !== $type and is_a($object, 'Illuminate\Database\Eloquent\Model')) {
// Twig doesn't support sandboxing on objects that implement ArrayAccess
// https://github.com/twigphp/Twig/issues/106#issuecomment-583737
// https://github.com/twigphp/Twig/pull/1863
//
// https://github.com/twigphp/Twig/issues/2878
if (Template::METHOD_CALL !== $type and $object instanceof ArrayAccess) {
// We can't easily find out if an attribute actually exists, so return true
if ($isDefinedTest) {
return true;
Expand All @@ -139,7 +145,7 @@ public static function attribute(
$env->getExtension(SandboxExtension::class)->checkPropertyAllowed($object, $item);
}

// Call the attribute, the Model object does the rest of the magic
// Call the attribute, the object does the rest of the magic
return $object->$item;
}

Expand Down

0 comments on commit 3b2068a

Please sign in to comment.