Skip to content

Commit 24f8ccb

Browse files
Merge branch '3.4' into 4.3
* 3.4: Fix tests on console cs fix Fix path to phpunit binary [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given
2 parents 5e7c473 + 090881c commit 24f8ccb

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
@@ -670,7 +670,7 @@ private function parseValue(string $value, int $flags, string $context)
670670
if (\in_array($value[0], ['!', '|', '>'], true) && self::preg_match('/^(?:'.self::TAG_PATTERN.' +)?'.self::BLOCK_SCALAR_HEADER_PATTERN.'$/', $value, $matches)) {
671671
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
672672

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

675675
if ('' !== $matches['tag'] && '!' !== $matches['tag']) {
676676
if ('!!binary' === $matches['tag']) {

Tests/ParserTest.php

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

21092109
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
21102110
}
2111+
2112+
public function testParseValueWithModifiers()
2113+
{
2114+
$yaml = <<<YAML
2115+
parameters:
2116+
abc: |+5 # plus five spaces indent
2117+
one
2118+
two
2119+
three
2120+
four
2121+
five
2122+
YAML;
2123+
$this->assertSame(
2124+
[
2125+
'parameters' => [
2126+
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
2127+
],
2128+
],
2129+
$this->parser->parse($yaml)
2130+
);
2131+
}
2132+
2133+
public function testParseValueWithNegativeModifiers()
2134+
{
2135+
$yaml = <<<YAML
2136+
parameters:
2137+
abc: |-3 # minus
2138+
one
2139+
two
2140+
three
2141+
four
2142+
five
2143+
YAML;
2144+
$this->assertSame(
2145+
[
2146+
'parameters' => [
2147+
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
2148+
],
2149+
],
2150+
$this->parser->parse($yaml)
2151+
);
2152+
}
21112153
}
21122154

21132155
class B

0 commit comments

Comments
 (0)