From aa6b8358161e4ef35299be06a5ff61bfcba46f6a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 7 Nov 2011 14:18:48 +0100 Subject: [PATCH] converted item parameter of Twig_Template::getAttribute() to string --- lib/Twig/Template.php | 2 ++ test/Twig/Tests/TemplateTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 77e5d04..73e1453 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -308,6 +308,8 @@ abstract class Twig_Template implements Twig_TemplateInterface */ protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { + $item = (string) $item; + // array if (Twig_TemplateInterface::METHOD_CALL !== $type) { if ((is_array($object) && array_key_exists($item, $object)) diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 8f94c89..874f4da 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -68,6 +68,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase 'defined' => 'defined', 'zero' => 0, 'null' => null, + '1' => 1, ); $objectArray = new Twig_TemplateArrayAccessObject; @@ -85,6 +86,8 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase array(true, 'defined', 'defined'), array(false, null, 'undefined'), array(true, 0, 'zero'), + array(true, 1, 1), + array(true, 1, 1.0), array(true, null, 'null'), ); $testObjects = array( @@ -99,6 +102,11 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $tests = array(); foreach ($testObjects as $testObject) { foreach ($basicTests as $test) { + // properties cannot be numbers + if ($testObject[0] instanceof stdClass && is_numeric($test[2])) { + continue; + } + $tests[] = array($test[0], $test[1], $testObject[0], $test[2], array(), $testObject[1]); } } @@ -154,6 +162,7 @@ class Twig_TemplateArrayAccessObject implements ArrayAccess 'defined' => 'defined', 'zero' => 0, 'null' => null, + '1' => 1, ); public function offsetExists($name) @@ -181,6 +190,7 @@ class Twig_TemplateMagicPropertyObject 'defined' => 'defined', 'zero' => 0, 'null' => null, + '1' => 1, ); public function __isset($name) @@ -201,6 +211,11 @@ class Twig_TemplateMethodObject return 'defined'; } + public function get1() + { + return 1; + } + public function getZero() { return 0; -- 1.7.2.5