Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 92bc19f

Browse filesBrowse files
committed
prevent notice for invalid octal numbers on PHP 7.4
1 parent cfa048c commit 92bc19f
Copy full SHA for 92bc19f

File tree

2 files changed

+20
-4
lines changed
Filter options

2 files changed

+20
-4
lines changed

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+10-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+10Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.