Skip to content

Commit 2375571

Browse files
Merge branch '3.4' into 4.3
* 3.4: [Cache] fix memory leak when using PhpArrayAdapter fix parsing negative octal numbers [SecurityBundle] Properly escape regex in AddSessionDomainConstraintPass [Config] never try loading failed classes twice with ClassExistenceResource
2 parents 324cf4b + 1b78a23 commit 2375571

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Inline.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,11 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
612612
// Optimize for returning strings.
613613
// no break
614614
case '+' === $scalar[0] || '-' === $scalar[0] || '.' === $scalar[0] || is_numeric($scalar[0]):
615+
if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
616+
$scalar = str_replace('_', '', (string) $scalar);
617+
}
618+
615619
switch (true) {
616-
case Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar):
617-
$scalar = str_replace('_', '', (string) $scalar);
618-
// omitting the break / return as integers are handled in the next case
619-
// no break
620620
case ctype_digit($scalar):
621621
$raw = $scalar;
622622
$cast = (int) $scalar;
@@ -626,7 +626,7 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
626626
$raw = $scalar;
627627
$cast = (int) $scalar;
628628

629-
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw);
629+
return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw);
630630
case is_numeric($scalar):
631631
case Parser::preg_match(self::getHexRegex(), $scalar):
632632
$scalar = str_replace('_', '', $scalar);

Tests/InlineTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,4 +720,20 @@ public function testUnfinishedInlineMap()
720720
$this->expectExceptionMessage('Unexpected end of line, expected one of ",}" at line 1 (near "{abc: \'def\'").');
721721
Inline::parse("{abc: 'def'");
722722
}
723+
724+
/**
725+
* @dataProvider getTestsForOctalNumbers
726+
*/
727+
public function testParseOctalNumbers($expected, $yaml)
728+
{
729+
self::assertSame($expected, Inline::parse($yaml));
730+
}
731+
732+
public function getTestsForOctalNumbers()
733+
{
734+
return [
735+
'positive octal number' => [28, '034'],
736+
'negative octal number' => [-28, '-034'],
737+
];
738+
}
723739
}

0 commit comments

Comments
 (0)