From faef73888e2b018e94aa2ce222d227c537ba979a Mon Sep 17 00:00:00 2001 From: Aleksandr Dankovtsev Date: Thu, 1 Aug 2019 14:16:39 +0300 Subject: [PATCH] [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given --- src/Symfony/Component/Yaml/Parser.php | 2 +- .../Component/Yaml/Tests/ParserTest.php | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 4f5c30e168..013810df7a 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -715,7 +715,7 @@ class Parser if (self::preg_match('/^(?:'.self::TAG_PATTERN.' +)?'.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) { $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : ''; - $data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers)); + $data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs((int) $modifiers)); if ('' !== $matches['tag']) { if ('!!binary' === $matches['tag']) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index d3217b6302..56dc748a18 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -2307,6 +2307,48 @@ YAML; $this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml)); } + + public function testParseValueWithModifiers() + { + $yaml = <<assertSame( + [ + 'parameters' => [ + 'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']), + ], + ], + $this->parser->parse($yaml) + ); + } + + public function testParseValueWithNegativeModifiers() + { + $yaml = <<assertSame( + [ + 'parameters' => [ + 'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']), + ], + ], + $this->parser->parse($yaml) + ); + } } class B