From: Fabien Potencier Date: Wed, 23 May 2012 05:50:33 +0000 (+0200) Subject: fixed a regression when using a number in template attributes (closes #733) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=573a36097146b319e5fb36546a0377c7440bbfe3;p=web%2Fkonrad%2Ftwig.git fixed a regression when using a number in template attributes (closes #733) --- diff --git a/CHANGELOG b/CHANGELOG index 5f4d0b8..eb53dc1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.8.2 (2012-XX-XX) + * fixed a regression when using a number in template attributes * fixed compiler when mbstring.func_overload is set to 2 * 1.8.1 (2012-05-17) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 1693596..7ecdba4 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -326,7 +326,7 @@ 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 = is_numeric($item) ? (int) $item : (string) $item; + $item = ctype_digit((string) $item) ? (int) $item : (string) $item; // array if (Twig_TemplateInterface::METHOD_CALL !== $type) { diff --git a/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test b/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test new file mode 100644 index 0000000..e18e110 --- /dev/null +++ b/test/Twig/Tests/Fixtures/regression/strings_like_numbers.test @@ -0,0 +1,8 @@ +--TEST-- +Twig does not confuse strings with integers in getAttribute() +--TEMPLATE-- +{{ hash['2e2'] }} +--DATA-- +return array('hash' => array('2e2' => 'works')) +--EXPECT-- +works