fix parsing negative octal numbers
This commit is contained in:
parent
59126e0f9c
commit
7ab53f9a39
@ -735,11 +735,11 @@ class Inline
|
||||
// Optimize for returning strings.
|
||||
// no break
|
||||
case '+' === $scalar[0] || '-' === $scalar[0] || '.' === $scalar[0] || is_numeric($scalar[0]):
|
||||
switch (true) {
|
||||
case Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar):
|
||||
if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
|
||||
$scalar = str_replace('_', '', (string) $scalar);
|
||||
// omitting the break / return as integers are handled in the next case
|
||||
// no break
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case ctype_digit($scalar):
|
||||
$raw = $scalar;
|
||||
$cast = (int) $scalar;
|
||||
@ -749,7 +749,7 @@ class Inline
|
||||
$raw = $scalar;
|
||||
$cast = (int) $scalar;
|
||||
|
||||
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw);
|
||||
return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw);
|
||||
case is_numeric($scalar):
|
||||
case Parser::preg_match(self::getHexRegex(), $scalar):
|
||||
$scalar = str_replace('_', '', $scalar);
|
||||
|
@ -781,4 +781,20 @@ class InlineTest extends TestCase
|
||||
$this->expectExceptionMessage('Unexpected end of line, expected one of ",}" at line 1 (near "{abc: \'def\'").');
|
||||
Inline::parse("{abc: 'def'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestsForOctalNumbers
|
||||
*/
|
||||
public function testParseOctalNumbers($expected, $yaml)
|
||||
{
|
||||
self::assertSame($expected, Inline::parse($yaml));
|
||||
}
|
||||
|
||||
public function getTestsForOctalNumbers()
|
||||
{
|
||||
return [
|
||||
'positive octal number' => [28, '034'],
|
||||
'negative octal number' => [-28, '-034'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user