-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Convert XML to PHP array with XMLUtils::convertDomElementToArray : numbers who start by "0" convert into octal number (which is wrong) #41532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, don't hesitate to create a pull-request with your solution, so the core team and the community will be able to easily review if it's the best way to do it! 👍 |
Hey, thanks for your report! |
Can you create a small example application that allows to reproduce your issue? |
@xabbuh I'm looking into this. |
…ring 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
Symfony version(s) affected: 5.2.5 (at least)
Description
If you have some value in your XML file with a number starting by "0" (example : 080000 ), XMLUtils::convertDomElementToArray will return "ArrivalTime" => 0, which isn't correct.
How to reproduce
Let's take the following XML file :
$xml_file = <?xml version="1.0"?><ResponseItinerary><Header><CruiseLineCode>SBN</CruiseLineCode><SubsystemId>3</SubsystemId><AgencyId1>58080</AgencyId1><AgencyId2>58080</AgencyId2><Currency/><AgencyConsumer/><TransactionCounter/></Header><Itinerary><GeneralInfo><Errors/><Warnings/><HowMuch>29</HowMuch></GeneralInfo><List ItineraryCode="E1N12BVN" PackageId="V175"><ListElement><DWeek>SAMEDI</DWeek><DepartureDate>11/12/2021</DepartureDate><PortName Code="GRW" Activity="">GREENWICH (LONDON)</PortName><ArrivalTime>090000</ArrivalTime><DepartureTime>000000</DepartureTime><Indicator/></ListElement></List></Itinerary></ResponseItinerary>;
Let's convert it into PHP file using XmlUtils Symfony class :
The "ArrivalTime" property shouldn't show 0, but 090000.
Possible Solution
Here's the solution :
private function is_octal($x) { return decoct(octdec($x)) == $x; }
change this
return '0' == $value[0] ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
into this
return self::is_octal($value) ? octdec($value) : (((string) $raw === (string) $cast) ? $cast : $raw);
The text was updated successfully, but these errors were encountered: