Skip to content

Commit

Permalink
bug #32910 [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter …
Browse files Browse the repository at this point in the history
…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: #32862

Commits
-------

faef738 [Yaml] PHP-8: Uncaught TypeError: abs() expects parameter 1 to be int or float, string given
  • Loading branch information
nicolas-grekas committed Aug 3, 2019
2 parents 9b41f67 + faef738 commit 9188261
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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 @@ -2267,6 +2267,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

0 comments on commit 9188261

Please sign in to comment.