8000 bug #36690 [Yaml] prevent notice for invalid octal numbers on PHP 7.4… · symfony/symfony@6340e87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6340e87

Browse files
committed
bug #36690 [Yaml] prevent notice for invalid octal numbers on PHP 7.4 (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] prevent notice for invalid octal numbers on PHP 7.4 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #34807 | License | MIT | Doc PR | Commits ------- 92bc19f prevent notice for invalid octal numbers on PHP 7.4
2 parents cfa048c + 92bc19f commit 6340e87

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -759,15 +759,21 @@ private static function evaluateScalar($scalar, $flags, $references = [])
759759

760760
switch (true) {
761761
case ctype_digit($scalar):
762-
$raw = $scalar;
762+
if ('0' === $scalar[0]) {
763+
return octdec(preg_replace('/[^0-7]/', '', $scalar));
764+
}
765+
763766
$cast = (int) $scalar;
764767

765-
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
768+
return ($scalar === (string) $cast) ? $cast : $scalar;
766769
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
767-
$raw = $scalar;
770+
if ('0' === $scalar[1]) {
771+
return -octdec(preg_replace('/[^0-7]/', '', substr($scalar, 1)));
772+
}
773+
768774
$cast = (int) $scalar;
769775

770-
return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw);
776+
return ($scalar === (string) $cast) ? $cast : $scalar;
771777
case is_numeric($scalar):
772778
case Parser::preg_match(self::getHexRegex(), $scalar):
773779
$scalar = str_replace('_', '', $scalar);

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,14 @@ public function phpConstTagWithEmptyValueProvider()
842842
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
843843
];
844844
}
845+
846+
public function testParsePositiveOctalNumberContainingInvalidDigits()
847+
{
848+
self::assertSame(342391, Inline::parse('0123456789'));
849+
}
850+
851+
public function testParseNegativeOctalNumberContainingInvalidDigits()
852+
{
853+
self::assertSame(-342391, Inline::parse('-0123456789'));
854+
}
845855
}

0 commit comments

Comments
 (0)
0