mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-05 15:07:11 +00:00
Replace strtolower() with strtr() when dealing with method names
This commit is contained in:
committed by
Fabien Potencier
parent
3853841c9f
commit
30feddef10
@@ -657,7 +657,7 @@ class ExpressionParser
|
||||
$stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
||||
}
|
||||
$value = $token->getValue();
|
||||
if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) {
|
||||
if (\in_array(strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), ['true', 'false', 'none', 'null'])) {
|
||||
throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$targets[] = new AssignNameExpression($value, $token->getLine());
|
||||
|
||||
+2
-2
@@ -299,7 +299,7 @@ class Parser implements \Twig_ParserInterface
|
||||
$this->reservedMacroNames = [];
|
||||
$r = new \ReflectionClass($this->env->getBaseTemplateClass());
|
||||
foreach ($r->getMethods() as $method) {
|
||||
$methodName = strtolower($method->getName());
|
||||
$methodName = strtr($method->getName(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
|
||||
|
||||
if ('get' === substr($methodName, 0, 3) && isset($methodName[3])) {
|
||||
$this->reservedMacroNames[] = substr($methodName, 3);
|
||||
@@ -307,7 +307,7 @@ class Parser implements \Twig_ParserInterface
|
||||
}
|
||||
}
|
||||
|
||||
return \in_array(strtolower($name), $this->reservedMacroNames);
|
||||
return \in_array(strtr($name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), $this->reservedMacroNames);
|
||||
}
|
||||
|
||||
public function addTrait($trait)
|
||||
|
||||
@@ -51,7 +51,7 @@ class SecurityPolicy implements SecurityPolicyInterface
|
||||
{
|
||||
$this->allowedMethods = [];
|
||||
foreach ($methods as $class => $m) {
|
||||
$this->allowedMethods[$class] = array_map('strtolower', \is_array($m) ? $m : [$m]);
|
||||
$this->allowedMethods[$class] = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class SecurityPolicy implements SecurityPolicyInterface
|
||||
}
|
||||
|
||||
$allowed = false;
|
||||
$method = strtolower($method);
|
||||
$method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
|
||||
foreach ($this->allowedMethods as $class => $methods) {
|
||||
if ($obj instanceof $class) {
|
||||
$allowed = \in_array($method, $methods);
|
||||
|
||||
+3
-3
@@ -628,7 +628,7 @@ abstract class Template implements \Twig_TemplateInterface
|
||||
|
||||
foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $refMethod) {
|
||||
// Accessing the environment from templates is forbidden to prevent untrusted changes to the environment
|
||||
if ('getenvironment' !== strtolower($refMethod->name)) {
|
||||
if ('getenvironment' !== strtr($refMethod->name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) {
|
||||
$methods[] = $refMethod->name;
|
||||
}
|
||||
}
|
||||
@@ -642,7 +642,7 @@ abstract class Template implements \Twig_TemplateInterface
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$cache[$method] = $method;
|
||||
$cache[$lcName = strtolower($method)] = $method;
|
||||
$cache[$lcName = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')] = $method;
|
||||
|
||||
if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) {
|
||||
$name = substr($method, 3);
|
||||
@@ -670,7 +670,7 @@ abstract class Template implements \Twig_TemplateInterface
|
||||
$call = false;
|
||||
if (isset(self::$cache[$class][$item])) {
|
||||
$method = self::$cache[$class][$item];
|
||||
} elseif (isset(self::$cache[$class][$lcItem = strtolower($item)])) {
|
||||
} elseif (isset(self::$cache[$class][$lcItem = strtr($item, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')])) {
|
||||
$method = self::$cache[$class][$lcItem];
|
||||
} elseif (isset(self::$cache[$class]['__call'])) {
|
||||
$method = $item;
|
||||
|
||||
Reference in New Issue
Block a user