Skip to content

Commit d03f489

Browse files
committed
Enforce string type for string operations
split: b40122acb6c4acafd4e04ff3cef4f202876eb2cb
1 parent 3949fcc commit d03f489

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Lexer/Scanner/AttributeScanner.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private function isTruncatedValue($expression)
3030
$expression = preg_replace('/
3131
"(?:\\\\[\\S\\s]|[^"\\\\])*"|
3232
\'(?:\\\\[\\S\\s]|[^\'\\\\])*\'
33-
/x', '0', $expression);
33+
/x', '0', (string) $expression);
3434
$expression = preg_replace('/\\s*(
3535
(\\[([^\\[\\]]+|(?1))*\\]) |
3636
(\\(([^\\(\\)]+|(?1))*\\)) |
@@ -42,6 +42,8 @@ private function isTruncatedValue($expression)
4242

4343
private function isTruncatedExpression(Reader $reader, &$expression)
4444
{
45+
$expression = (string) $expression;
46+
4547
if (mb_substr($expression, -3) === 'new' || mb_substr($expression, -5) === 'clone') {
4648
$expression .= $reader->getLastPeekResult();
4749
$reader->consume();

Lexer/Scanner/FilterScanner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function scan(State $state)
5555
$token = $state->createToken(TextToken::class);
5656
if ($maxIndent > 0 && $maxIndent < INF) {
5757
foreach ($lines as &$line) {
58-
$line = mb_substr($line, $maxIndent) ?: '';
58+
$line = mb_substr((string) $line, $maxIndent);
5959
}
6060
}
6161
$token->setValue(implode("\n", $lines));

Lexer/Scanner/MultilineScanner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function yieldLines(State $state, array $lines, LineAnalyzer $analyzer)
9292
if ($maxIndent > 0 && $maxIndent < INF) {
9393
foreach ($lines as &$line) {
9494
if (count($line) && is_string($line[0])) {
95-
$line[0] = mb_substr($line[0], $maxIndent) ?: '';
95+
$line[0] = mb_substr((string) $line[0], $maxIndent);
9696
}
9797
}
9898
}

Lexer/Scanner/TextScanner.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class TextScanner implements ScannerInterface
1919

2020
private function isTextStartToTrim(State $state, $text)
2121
{
22-
return in_array(mb_substr($text, 0, 1), [' ', "\t"]) && !$state->isAfterInterpolation();
22+
return in_array(mb_substr((string) $text, 0, 1), [' ', "\t"]) && !$state->isAfterInterpolation();
2323
}
2424

2525
private function leftTrimValueIfNotAfterInterpolation(State $state, TextToken $token)
2626
{
2727
$text = $token->getValue();
2828

2929
if ($this->isTextStartToTrim($state, $text)) {
30-
$token->setValue(mb_substr($text, 1) ?: '');
30+
$token->setValue(mb_substr((string) $text, 1));
3131
}
3232
}
3333

@@ -87,7 +87,7 @@ public function scan(State $state)
8787
$text = mb_substr($text, 1);
8888
}
8989

90-
$text = preg_replace('/\\\\([#!]\\[|#\\{)/', '$1', $text);
90+
$text = preg_replace('/\\\\([#!]\\[|#{)/', '$1', $text);
9191
$token->setValue($text);
9292

9393
yield $state->endToken($token);

0 commit comments

Comments
 (0)