fixed ArrayObject access with a null value

This commit is contained in:
Yonel Ceruto
2018-09-19 17:55:05 -04:00
parent 9d36daf19e
commit 80e65b4c73
2 changed files with 3 additions and 3 deletions
+1 -3
View File
@@ -508,9 +508,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
if (self::METHOD_CALL !== $type) { if (self::METHOD_CALL !== $type) {
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
if ((is_array($object) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object))) if ((is_array($object) || $object instanceof ArrayAccess) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object))) {
|| ($object instanceof ArrayAccess && isset($object[$arrayItem]))
) {
if ($isDefinedTest) { if ($isDefinedTest) {
return true; return true;
} }
+2
View File
@@ -315,6 +315,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase
]; ];
$objectArray = new Twig_TemplateArrayAccessObject(); $objectArray = new Twig_TemplateArrayAccessObject();
$arrayObject = new ArrayObject($array);
$stdObject = (object) $array; $stdObject = (object) $array;
$magicPropertyObject = new Twig_TemplateMagicPropertyObject(); $magicPropertyObject = new Twig_TemplateMagicPropertyObject();
$propertyObject = new Twig_TemplatePropertyObject(); $propertyObject = new Twig_TemplatePropertyObject();
@@ -346,6 +347,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase
// array(object, type of fetch) // array(object, type of fetch)
[$array, $arrayType], [$array, $arrayType],
[$objectArray, $arrayType], [$objectArray, $arrayType],
[$arrayObject, $anyType],
[$stdObject, $anyType], [$stdObject, $anyType],
[$magicPropertyObject, $anyType], [$magicPropertyObject, $anyType],
[$methodObject, $methodType], [$methodObject, $methodType],