Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30c3913

Browse files
[Config] In XmlUtils, avoid converting from octal every string starting with a 0
1 parent 677ca9c commit 30c3913

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function getDataForPhpize(): array
169169
[1, '1'],
170170
[-1, '-1'],
171171
[0777, '0777'],
172+
[-511, '-0777'],
173+
['0877', '0877'],
172174
[255, '0xFF'],
173175
[100.0, '1e2'],
174176
[-120.0, '-1.2E2'],

src/Symfony/Component/Config/Util/XmlUtils.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,11 @@ public static function phpize($value)
236236
case 'null' === $lowercaseValue:
237237
return null;
238238
case ctype_digit($value):
239-
$raw = $value;
240-
$cast = (int) $value;
241-
242-
return '0' == $value[0] ? octdec($value) : (($raw === (string) $cast) ? $cast : $raw);
243239
case isset($value[1]) && '-' === $value[0] && ctype_digit(substr($value, 1)):
244240
$raw = $value;
245241
$cast = (int) $value;
246242

247-
return '0' == $value[1] ? octdec($value) : (($raw === (string) $cast) ? $cast : $raw);
243+
return self::isOctal($value) ? \intval($value, 8) : (($raw === (string) $cast) ? $cast : $raw);
248244
case 'true' === $lowercaseValue:
249245
return true;
250246
case 'false' === $lowercaseValue:
@@ -281,4 +277,13 @@ protected static function getXmlErrors($internalErrors)
281277

282278
return $errors;
283279
}
280+
281+
private static function isOctal(string $str): bool
282+
{
283+
if ('-' === $str[0]) {
284+
$str = substr($str, 1);
285+
}
286+
287+
return $str === '0'.decoct(\intval($str, 8));
288+
}
284289
}

0 commit comments

Comments
 (0)