Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given #32910

Merged
merged 1 commit into from Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -715,7 +715,7 @@ private function parseValue($value, $flags, $context)
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']) {
Expand Down
42 changes: 42 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -2307,6 +2307,48 @@ public function testMultiLineComment()

$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
}

public function testParseValueWithModifiers()
{
$yaml = <<<YAML
parameters:
abc: |+5 # plus five spaces indent
one
two
three
four
five
YAML;
$this->assertSame(
[
'parameters' => [
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
],
],
$this->parser->parse($yaml)
);
}

public function testParseValueWithNegativeModifiers()
{
$yaml = <<<YAML
parameters:
abc: |-3 # minus
one
two
three
four
five
YAML;
$this->assertSame(
[
'parameters' => [
'abc' => implode("\n", ['one', 'two', 'three', 'four', 'five']),
],
],
$this->parser->parse($yaml)
);
}
}

class B
Expand Down