Fix sign loss when scanning negative sexagesimal scalars#806
Open
chatman-media wants to merge 1 commit into
Open
Fix sign loss when scanning negative sexagesimal scalars#806chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
ScalarScanner#tokenize only applied the leading minus/plus to the first colon-separated segment (via String#to_i/#to_f), so a value like "-190:20:30" came out as -682770 instead of -685230 because the 20 and 30 parts kept their positive sign. Strip the sign once up front and apply it to the final sum instead, matching the yaml.org sexagesimal spec (and what PyYAML does). Added regression tests for the negative int and float cases.
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.
Ran into this while parsing some YAML with negative time offsets.
ScalarScanner#tokenizesplits sexagesimal values like190:20:30on:and parses each segment withto_i/to_f, but the minus sign only sticks to the first segment since that's the only oneString#to_iactually sees it on. So-190:20:30comes out as-682770instead of-685230— the20and30parts silently stay positive and get added instead of subtracted.Same bug in both the int and float branches. Fix strips the sign once up front and applies it to the final sum, which matches how PyYAML (and the yaml.org spec) handle this. Added a couple of regression tests for negative sexagesimal int/float.