Skip to content

Commit ab1e9b9

Browse files
committed
bug #44537 [Config] In XmlUtils, avoid converting from octal every string starting with a 0 (alexandre-daubois)
This PR was merged into the 4.4 branch. Discussion ---------- [Config] In XmlUtils, avoid converting from octal every string starting with a 0 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #41532 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | N/A One word on the use of `intval` instead of `octdec`: `octdec` leads to deprecation notices when testing a non-octal string: ``` Invalid characters passed for attempted conversion, these have been ignored ``` While `intval` doesn't, which worth the use in my opinion. Commits ------- 30c3913 [Config] In XmlUtils, avoid converting from octal every string starting with a 0
2 parents 068674b + 30c3913 commit ab1e9b9

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)
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