Repository navigation
Conversation
jeremyevans
left a comment
There was a problem hiding this comment.
parse is often called with untrusted data, so I'm not sure we want to issue a warning in that case.
However, we should probably treat +2500 like +25:00 and not set the offset in that case. Can you modify the PR to only do that?
|
Thanks for the review. I started making this change and found two existing tests that rely on the compact form accepting large hours:
Making the compact form reject out-of-range values the same way the colon form does (hour > 23, minute/second > 59) would change those cases to have no offset. Should I update those tests as part of this change, or did you have a narrower rule in mind for the compact form? |
|
I would change both of the tests. |
date_zone_to_diff_frac validated the hour/minute/second ranges for the colon form of a zone offset (+25:00, +12:60), returning Qnil so the offset is not set, but the compact form (+2500, +1260) had no range checks at all: _parse returned an offset of 90000 seconds for +2500, and DateTime.parse applied a wrong 13-hour offset for +1260. Add the same range checks to the compact branch, so an out-of-range compact offset does not set the offset, matching the colon form. Update the two existing tests that expected the permissive behavior: the RFC 2822 -9959/+9959 cases in test__parse now expect no offset, and test_strftime__offset no longer round-trips +2400/-2400 (they now parse with offset 0, like +2430/-2430 and the colon forms).
2ab4e23 to
cbeaeeb
Compare
|
Thank you — I've updated the PR along those lines, and changed both tests.
The full suite passes. |
As discussed, this now takes the narrower approach: no warning, and out-of-range compact zone offsets are treated exactly like the colon form.
date_zone_to_diff_fracrange-checks the colon form (+25:00,+12:60) and returnsQnilso the offset is not set, but the compact form had no range checks at all:DateTime._parse('2001-02-03T04:05:06+2500')reportedoffset: 90000DateTime.parse('2001-02-03T04:05:06+1260')applied a wrong 13-hour offsetThe compact branch now applies the same hour/minute/second range checks, so those offsets are not set (
offset: nilfrom_parse, offset 0 fromparse), matching+25:00/+12:60.Existing tests changed, as suggested:
test__parse: the RFC 2822-9959/+9959cases now expect no offset (the zone string is still reported).test_strftime__offset:+2400/-2400no longer round-trip; they are grouped with+2430/-2430as parsing with offset 0. The oldassert_warning(/invalid offset/)expectation for+2430went away with this: that warning came from the constructor path when_parsestill returned the out-of-range offset, and the colon form never warned here.New tests:
test__parse_invalid_offset_without_colonandtest_parse_invalid_offset_without_colon. The full test suite passes.