Skip to content

Commit

Permalink
bug #2356 do not overridde case-insentive cache entries (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x branch.

Discussion
----------

do not overridde case-insentive cache entries

This will fix #2343.

Commits
-------

2c153bd do not overridde case-insentive cache entries
  • Loading branch information
fabpot committed Jan 11, 2017
2 parents 9ef01e8 + 2c153bd commit 0f2cbf5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Twig/Extension/Core.php
Expand Up @@ -1486,10 +1486,10 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object,
$methods = get_class_methods($object);
sort($methods);
$lcMethods = array_map('strtolower', $methods);
$cache = array();
$classCache = array();
foreach ($methods as $i => $method) {
$cache[$method] = $method;
$cache[$lcName = $lcMethods[$i]] = $method;
$classCache[$method] = $method;
$classCache[$lcName = $lcMethods[$i]] = $method;

if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) {
$name = substr($method, 3);
Expand All @@ -1507,12 +1507,15 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object,
continue;
}

if (!isset($cache[$name])) {
$cache[$name] = $method;
$cache[$lcName] = $method;
if (!isset($classCache[$name])) {
$classCache[$name] = $method;
}

if (!isset($classCache[$lcName])) {
$classCache[$lcName] = $method;
}
}
$cache[$class] = $cache;
$cache[$class] = $classCache;
}

$call = false;
Expand Down
5 changes: 5 additions & 0 deletions test/Twig/Tests/TemplateTest.php
Expand Up @@ -582,6 +582,11 @@ public function isBaz()
}

public function getBaz()
{
return 'Baz';
}

public function baz()
{
return 'baz';
}
Expand Down

0 comments on commit 0f2cbf5

Please sign in to comment.