mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 03:57:21 +00:00
Merge branch '3.x' into 4.x
* 3.x: Make `in_array()` calls strict
This commit is contained in:
@@ -30,7 +30,7 @@ class CacheTokenParser extends AbstractTokenParser
|
||||
$tags = null;
|
||||
while ($stream->test(Token::NAME_TYPE)) {
|
||||
$k = $stream->getCurrent()->getValue();
|
||||
if (!\in_array($k, ['ttl', 'tags'])) {
|
||||
if (!\in_array($k, ['ttl', 'tags'], true)) {
|
||||
throw new SyntaxError(\sprintf('Unknown "%s" configuration.', $k), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ final class Cva
|
||||
if ('class' === $compoundName) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($recipes[$compoundName]) || !\in_array($recipes[$compoundName], (array) $compoundValues)) {
|
||||
if (!isset($recipes[$compoundName]) || !\in_array($recipes[$compoundName], (array) $compoundValues, true)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ final class Extensions
|
||||
public static function getFilter(string $name): array
|
||||
{
|
||||
foreach (self::EXTENSIONS as $extension) {
|
||||
if (\in_array($name, $extension['filters'])) {
|
||||
if (\in_array($name, $extension['filters'], true)) {
|
||||
return [$extension['class_name'], $extension['package']];
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ final class Extensions
|
||||
public static function getFunction(string $name): array
|
||||
{
|
||||
foreach (self::EXTENSIONS as $extension) {
|
||||
if (\in_array($name, $extension['functions'])) {
|
||||
if (\in_array($name, $extension['functions'], true)) {
|
||||
return [$extension['class_name'], $extension['package']];
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ final class Extensions
|
||||
public static function getTag(string $name): array
|
||||
{
|
||||
foreach (self::EXTENSIONS as $extension) {
|
||||
if (\in_array($name, $extension['tags'])) {
|
||||
if (\in_array($name, $extension['tags'], true)) {
|
||||
return [$extension['class_name'], $extension['package']];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1771,7 +1771,7 @@ final class CoreExtension extends AbstractExtension
|
||||
} elseif ('h' === $lcName[0] && str_starts_with($lcName, 'has')) {
|
||||
$name = substr($method, 3);
|
||||
$lcName = substr($lcName, 3);
|
||||
if (\in_array('is'.$lcName, $lcMethods)) {
|
||||
if (\in_array('is'.$lcName, $lcMethods, true)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,7 @@ class FileExtensionEscapingStrategy
|
||||
*/
|
||||
public static function guess(string $name)
|
||||
{
|
||||
if (\in_array(substr($name, -1), ['/', '\\'])) {
|
||||
if (\in_array(substr($name, -1), ['/', '\\'], true)) {
|
||||
return 'html'; // return html for directories
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -351,7 +351,7 @@ class Lexer
|
||||
// operators
|
||||
if (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
|
||||
$operator = preg_replace('/\s+/', ' ', $match[0]);
|
||||
if (\in_array($operator, $this->openingBrackets)) {
|
||||
if (\in_array($operator, $this->openingBrackets, true)) {
|
||||
$this->checkBrackets($operator);
|
||||
}
|
||||
$this->pushToken(Token::OPERATOR_TYPE, $operator);
|
||||
@@ -582,9 +582,9 @@ class Lexer
|
||||
private function checkBrackets(string $code): void
|
||||
{
|
||||
// opening bracket
|
||||
if (\in_array($code, $this->openingBrackets)) {
|
||||
if (\in_array($code, $this->openingBrackets, true)) {
|
||||
$this->brackets[] = [$code, $this->lineno];
|
||||
} elseif (\in_array($code, $this->closingBrackets)) {
|
||||
} elseif (\in_array($code, $this->closingBrackets, true)) {
|
||||
// closing bracket
|
||||
if (!$this->brackets) {
|
||||
throw new SyntaxError(\sprintf('Unexpected "%s".', $code), $this->lineno, $this->source);
|
||||
|
||||
@@ -148,7 +148,7 @@ final class EscaperNodeVisitor implements NodeVisitorInterface
|
||||
$safe = $this->safeAnalysis->getSafe($expression);
|
||||
}
|
||||
|
||||
return \in_array($type, $safe) || \in_array('all', $safe);
|
||||
return \in_array($type, $safe, true) || \in_array('all', $safe, true);
|
||||
}
|
||||
|
||||
private function needEscaping(): string|false
|
||||
|
||||
@@ -139,7 +139,7 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
|
||||
}
|
||||
|
||||
// optimize access to loop targets
|
||||
elseif ($node instanceof ContextVariable && \in_array($node->getAttribute('name'), $this->loopsTargets)) {
|
||||
elseif ($node instanceof ContextVariable && \in_array($node->getAttribute('name'), $this->loopsTargets, true)) {
|
||||
$node->setAttribute('always_defined', true);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\in_array('html_attr', $bucket['value'])) {
|
||||
if (\in_array('html_attr', $bucket['value'], true)) {
|
||||
$bucket['value'][] = 'html';
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
|
||||
$this->setSafe($node, ['all']);
|
||||
} elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof ContextVariable) {
|
||||
$name = $node->getNode('node')->getAttribute('name');
|
||||
if (\in_array($name, $this->safeVars)) {
|
||||
if (\in_array($name, $this->safeVars, true)) {
|
||||
$this->setSafe($node, ['all']);
|
||||
}
|
||||
}
|
||||
@@ -138,11 +138,11 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
|
||||
return [];
|
||||
}
|
||||
|
||||
if (\in_array('all', $a)) {
|
||||
if (\in_array('all', $a, true)) {
|
||||
return $b;
|
||||
}
|
||||
|
||||
if (\in_array('all', $b)) {
|
||||
if (\in_array('all', $b, true)) {
|
||||
return $a;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface
|
||||
}
|
||||
|
||||
$string = (string) $string;
|
||||
} elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) {
|
||||
} elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'], true)) {
|
||||
// we return the input as is (which can be of any type)
|
||||
return $string;
|
||||
}
|
||||
|
||||
@@ -82,19 +82,19 @@ final class SecurityPolicy implements SecurityPolicyInterface
|
||||
public function checkSecurity($tags, $filters, $functions): void
|
||||
{
|
||||
foreach ($tags as $tag) {
|
||||
if (!\in_array($tag, $this->allowedTags)) {
|
||||
if (!\in_array($tag, $this->allowedTags, true)) {
|
||||
throw new SecurityNotAllowedTagError(\sprintf('Tag "%s" is not allowed.', $tag), $tag);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (!\in_array($filter, $this->allowedFilters)) {
|
||||
if (!\in_array($filter, $this->allowedFilters, true)) {
|
||||
throw new SecurityNotAllowedFilterError(\sprintf('Filter "%s" is not allowed.', $filter), $filter);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($functions as $function) {
|
||||
if (!\in_array($function, $this->allowedFunctions)) {
|
||||
if (!\in_array($function, $this->allowedFunctions, true)) {
|
||||
throw new SecurityNotAllowedFunctionError(\sprintf('Function "%s" is not allowed.', $function), $function);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ final class SecurityPolicy implements SecurityPolicyInterface
|
||||
$allowed = false;
|
||||
$method = strtolower($method);
|
||||
foreach ($this->allowedMethods as $class => $methods) {
|
||||
if ($obj instanceof $class && \in_array($method, $methods)) {
|
||||
if ($obj instanceof $class && \in_array($method, $methods, true)) {
|
||||
$allowed = true;
|
||||
break;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ final class SecurityPolicy implements SecurityPolicyInterface
|
||||
{
|
||||
$allowed = false;
|
||||
foreach ($this->allowedProperties as $class => $properties) {
|
||||
if ($obj instanceof $class && \in_array($property, \is_array($properties) ? $properties : [$properties])) {
|
||||
if ($obj instanceof $class && \in_array($property, \is_array($properties) ? $properties : [$properties], true)) {
|
||||
$allowed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ final class Token
|
||||
|
||||
return $this->type === $type && (
|
||||
null === $values
|
||||
|| (\is_array($values) && \in_array($this->value, $values))
|
||||
|| (\is_array($values) && \in_array($this->value, $values, true))
|
||||
|| $this->value == $values
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ final class GuardTokenParser extends AbstractTokenParser
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
$typeToken = $stream->expect(Token::NAME_TYPE);
|
||||
if (!\in_array($typeToken->getValue(), ['function', 'filter', 'test'])) {
|
||||
if (!\in_array($typeToken->getValue(), ['function', 'filter', 'test'], true)) {
|
||||
throw new SyntaxError(\sprintf('Supported guard types are function, filter and test, "%s" given.', $typeToken->getValue()), $typeToken->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$method = 'get'.$typeToken->getValue();
|
||||
|
||||
Reference in New Issue
Block a user