Support ISO-8601 expanded years in XML dates (fix panic on dates outside 0000-9999) - #195
Open
gaoflow wants to merge 1 commit into
Open
Support ISO-8601 expanded years in XML dates (fix panic on dates outside 0000-9999)#195gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
Dates outside 0000-9999 (valid in binary plists, which store an f64 offset from the 2001 epoch) made to_xml_format panic, which took out to_writer_xml, Debug, and serde Serialize. from_xml_format also could not read the expanded-year strings Apple writes. Keep RFC 3339 for years 0000-9999 and format/parse the wider range directly, matching plutil byte for byte (e.g. 11476-08-15T05:20:00Z, -29719-..., -001-... for year -1). Invalid or unrepresentable strings return InvalidXmlDate instead of panicking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Date::to_xml_formatpanics on any date whose year falls outside 0000-9999.Binary plists store dates as an
f64offset from the 2001 epoch, so such dates arevalid and round-trip fine through Apple's tools; the common "read a binary plist,
re-serialize as XML" path then aborts the process on a file
plutilconsiders OK.Repro (year 11476,
plutil -lintreports OK):There are two panic sites, both in the date <-> string layer:
SystemTime -> OffsetDateTimeoverflows insidetime.time's RFC 3339 formatter rejects the year, and the.unwrap()on thatErrpanics.They surface through every path that stringifies a
Date:to_writer_xml/to_file_xml,impl Debug for Date, and serdeSerialize. The read side is themirror image:
from_xml_formatcan't parse the expanded-year strings Apple writes(
11476-...,-29719-...), so a plist written byplutilcan't be read back.The fix keeps
time's RFC 3339 for years 0000-9999 (output unchanged, includingsub-second precision) and handles the expanded range directly, byte-for-byte with
plutil:11476-08-15T05:20:00Z,33658-09-27T01:46:40Z-29719-04-05T22:13:20Z,-001-11-28T00:00:00Z(Apple pads the year%04d-style,so year -1 is
-001, not-0001)timecan't produce this itself: even withlarge-datesits formatter emits+11476/-0001rather than Apple's11476/-001, and its year range(±999999) is narrower than the plist date domain (
plutilprints year 285,200,616for a large enough
f64). So the expanded range uses a small proleptic-Gregorianconversion. Out-of-range or malformed strings return
InvalidXmlDateinstead ofpanicking.
New tests cover the 9999/10000 boundary, far past/future and negative years against
plutil's output, the read/write round-trip, theDebugpath, and rejection ofinvalid dates.
cargo test --all-featurespasses.This lines up with the Apple-compatibility goal in #118.
One thing left out on purpose: for in-range dates rust-plist still emits sub-second
precision (e.g.
...00.5Z) whereplutiltruncates to whole seconds (related to#13). I kept in-range output unchanged to avoid touching round-trip behaviour, but
can fold that in if you'd like.