fix(naive_time): enforce exact width when parsing %H%M%S#1710
Open
kumarUjjawal wants to merge 1 commit intochronotope:mainfrom
Open
fix(naive_time): enforce exact width when parsing %H%M%S#1710kumarUjjawal wants to merge 1 commit intochronotope:mainfrom
kumarUjjawal wants to merge 1 commit intochronotope:mainfrom
Conversation
Member
|
I think this is too incompatible for the 0.4.x release (as can be witnessed from all the test failures). We could take this on in the 0.5.x branch (if it isn't there already, I forget). |
Author
|
That makes sense. |
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.
Summary
Fixes #1697: NaiveTime::parse_from_str was accepting inputs shorter than the expected length for format strings like "%H%M%S". For example, "01023" was being parsed as 01:02:03, which is incorrect.
According to the documentation:
Bug
However,
NaiveTime::parse_from_str("01023", "%H%M%S")silently succeeds, returning01:02:03. I expected it to fail due to input being too short for%H%M%S(which should be 6 digits). This can lead to subtle bugs if users pass malformed data.Examples
"010233"%H%M%S01:02:33✅"0102334"%H%M%S"01023"%H%M%S01:02:03❌Fix
I modified
parse_internalto enforce exact width parsing for numeric fields like%H,%M,%S, etc., rejecting inputs that are too short or too long.I also updated/added test cases to reflect this.
Open Questions
strict-numeric) to avoid breaking changes?Why This Matters
The current behavior contradicts the documentation and can lead to unexpected results when parsing time strings. Enforcing exact width aligns with user expectations and format specifiers.
Please let me know if this direction makes sense. I’d be happy to:
Closes #1697