Skip to content

Commit 59ee8f4

Browse files
author
Aleksandr Dankovtsev
committed
[Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given
1 parent ec0045b commit 59ee8f4

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
@@ -2307,6 +2307,48 @@ public function testMultiLineComment()
23072307

23082308
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
23092309
}
2310+
2311+
public function testParseValueWithModifiers()
2312+
{
2313+
$yaml = <<<YAML
2314+
parameters:
2315+
abc: |+5 # plus five spaces indent
2316+
one
2317+
two
2318+
three
2319+
four
2320+
five
2321+
YAML;
2322+
$this->assertSame(
2323+
[
2324+
'parameters' => [
2325+
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
2326+
],
2327+
],
2328+
$this->parser->parse($yaml)
2329+
);
2330+
}
2331+
2332+
public function testParseValueWithNegativeModifiers()
2333+
{
2334+
$yaml = <<<YAML
2335+
parameters:
2336+
abc: |-3 # minus
2337+
one
2338+
two
2339+
three
2340+
four
2341+
five
2342+
YAML;
2343+
$this->assertSame(
2344+
[
2345+
'parameters' => [
2346+
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
2347+
],
2348+
],
2349+
$this->parser->parse($yaml)
2350+
);
2351+
}
23102352
}
23112353

23122354
class B

0 commit comments

Comments
 (0)