Skip to content

Commit 090881c

Browse files
bug #32910 [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given (Aleksandr Dankovtsev)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? |no | BC breaks? | no | Deprecations? |no | Tests pass? | yes | License | MIT In additional for PR: symfony/symfony#32862 Commits ------- faef73888e [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given
2 parents a551af1 + 59ee8f4 commit 090881c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ private function parseValue($value, $flags, $context)
715715
if (self::preg_match('/^(?:'.self::TAG_PATTERN.' +)?'.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) {
716716
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
717717

718-
$data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
718+
$data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs((int) $modifiers));
719719

720720
if ('' !== $matches['tag']) {
721721
if ('!!binary' === $matches['tag']) {

Tests/ParserTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,48 @@ public function testMultiLineComment()
22672267

22682268
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
22692269
}
2270+
2271+
public function testParseValueWithModifiers()
2272+
{
2273+
$yaml = <<<YAML
2274+
parameters:
2275+
abc: |+5 # plus five spaces indent
2276+
one
2277+
two
2278+
three
2279+
four
2280+
five
2281+
YAML;
2282+
$this->assertSame(
2283+
[
2284+
'parameters' => [
2285+
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
2286+
],
2287+
],
2288+
$this->parser->parse($yaml)
2289+
);
2290+
}
2291+
2292+
public function testParseValueWithNegativeModifiers()
2293+
{
2294+
$yaml = <<<YAML
2295+
parameters:
2296+
abc: |-3 # minus
2297+
one
2298+
two
2299+
three
2300+
four
2301+
five
2302+
YAML;
2303+
$this->assertSame(
2304+
[
2305+
'parameters' => [
2306+
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
2307+
],
2308+
],
2309+
$this->parser->parse($yaml)
2310+
);
2311+
}
22702312
}
22712313

22722314
class B

0 commit comments

Comments
 (0)