Skip to content

Commit 0f7ccdb

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

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-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+
['-0777', '-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: 6 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) ? octdec($value) : (($raw === (string) $cast) ? $cast : $raw);
248244
case 'true' === $lowercaseValue:
249245
return true;
250246
case 'false' === $lowercaseValue:
@@ -281,4 +277,9 @@ protected static function getXmlErrors($internalErrors)
281277

282278
return $errors;
283279
}
280+
281+
private static function isOctal(string $str): bool
282+
{
283+
return $str === '0'.decoct(\intval($str, 8));
284+
}
284285
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy