Fix for bug #101 : make magic calls case-sensitive in subscript expressions (closes #101)

This commit is contained in:
Arnaud Le Blanc
2010-08-15 22:03:36 +02:00
committed by Fabien Potencier
parent 47c44e477c
commit 839f16145e
3 changed files with 8 additions and 4 deletions
+1
View File
@@ -5,6 +5,7 @@ Backward incompatibilities:
* the odd and even filters are now tests:
{{ foo|odd }} must now be written {{ foo is odd }}
* fixed subscript expressions when calling __call() (methods now keep the case)
* added a "trans" filter
* added "test" feature (accessible via the "is" operator)
* removed the debug tag (should be done in an extension)
+3 -3
View File
@@ -138,10 +138,10 @@ abstract class Twig_Template implements Twig_TemplateInterface
}
// object method
$item = strtolower($item);
if (isset(self::$cache[$class]['methods'][$item])) {
$lcItem = strtolower($item);
if (isset(self::$cache[$class]['methods'][$lcItem])) {
$method = $item;
} elseif (isset(self::$cache[$class]['methods']['get'.$item])) {
} elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
$method = 'get'.$item;
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
$method = $item;
+4 -1
View File
@@ -41,14 +41,17 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
// METHOD
array('bar', $object, 'bar', array(), $methodType),
array('bar', $object, 'getBar', array(), $methodType),
array('bar', $object, 'getbar', array(), $methodType),
array('foobar', $object, 'foobar', array(), $methodType),
array('babar', $object, 'babar', array(), $methodType),
array('babarStatic', $object, 'babarStatic', array(), $methodType),
array('__call_baz', $objectMagic, 'baz', array(), $methodType),
array('__call_Baz', $objectMagic, 'Baz', array(), $methodType),
// ANY
array('foo', $object, 'foo', array(), $anyType),
array('foo', $objectMagic, 'foo', array(), $anyType),
array('Foo', $objectMagic, 'Foo', array(), $anyType),
array(null, $object, 'null', array(), $anyType),
);
@@ -134,7 +137,7 @@ class Twig_TemplateObjectArrayAccess implements ArrayAccess
class Twig_TemplateObjectMagic
{
public $attributes = array('foo' => 'foo');
public $attributes = array('foo' => 'foo', 'Foo' => 'Foo');
public function __isset($name)
{