Skip to content
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

Permit Parsing Of Leading Zeros #1973

Merged
merged 5 commits into from
Jul 19, 2022

Conversation

isomarcte
Copy link
Contributor

This commit changes BiggerDecimal.parseBiggerDecimalUnsafe to permit parsing of leading '0' characters, and by extension allows all of our numeric codecs to tolerate decoding JsonString values which represent numbers with leading zeros. This is more in line with the fromString methods on the various numeric classes.

Note, this change should be given some serious scrutiny. It appears that the original authors had at some time explicitly forbade this behavior, as noted by the existence of the AFTER_ZERO state as well as the explicit test case for invalid input including the String "01".

I've searched around the issues and I couldn't find any reasoning for this decision, so I still think being lenient here is the right choice, but please double check me.

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2022

Codecov Report

Merging #1973 (9d39fc5) into main (8f5f20c) will increase coverage by 0.10%.
The diff coverage is 91.54%.

@@            Coverage Diff             @@
##             main    #1973      +/-   ##
==========================================
+ Coverage   85.98%   86.08%   +0.10%     
==========================================
  Files          74       74              
  Lines        2554     2544      -10     
  Branches      120      109      -11     
==========================================
- Hits         2196     2190       -6     
+ Misses        358      354       -4     
Flag Coverage Δ
2.12.15 85.88% <91.54%> (+0.14%) ⬆️
2.13.8 86.08% <91.54%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/main/scala/io/circe/numbers/BiggerDecimal.scala 88.81% <91.54%> (+1.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f5f20c...9d39fc5. Read the comment docs.

@isomarcte
Copy link
Contributor Author

@zarthross I can't seem to reproduce that failure locally, and I don't think it is related to this PR.

@isomarcte isomarcte force-pushed the permit-parsing-leading-zeros branch from bb0d3ee to 01a5584 Compare June 11, 2022 18:10
@isomarcte
Copy link
Contributor Author

@zarthross errors gone on a re-run. The errors were relating to the Printer's sorting of object keys, but like I said, the didn't seem related to this PR.

@armanbilge
Copy link
Contributor

Perhaps it was #1911 you saw?

This commit changes `BiggerDecimal.parseBiggerDecimalUnsafe` to permit parsing of leading '0' characters, and by extension allows all of our numeric codecs to tolerate decoding `JsonString` values which represent numbers with leading zeros. This is more in line with the `fromString` methods on the various numeric classes.

Note, this change should be given some serious scrutiny. It appears that the original authors had at some time explicitly forbade this behavior, as noted by the existence of the `AFTER_ZERO` state as well as the explicit test case for invalid input including the `String` `"01"`.
p
I've searched around the issues and I couldn't find any reasoning for this decision, so I still think being lenient here is the right choice, but please double check me.
@isomarcte isomarcte force-pushed the permit-parsing-leading-zeros branch from 2cf9c26 to a5ef603 Compare June 13, 2022 15:33
@isomarcte
Copy link
Contributor Author

@armanbilge I bet it was.

@isomarcte
Copy link
Contributor Author

@zarthross thoughts here?

Copy link
Member

@zarthross zarthross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just 2 minor things I'd like fixed.

@isomarcte isomarcte requested a review from zarthross July 11, 2022 18:29
Copy link
Member

@zmccoy zmccoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the minor naming nitpick I think this looks good.

@zarthross zarthross merged commit 4afbdb2 into circe:main Jul 19, 2022
@isomarcte isomarcte deleted the permit-parsing-leading-zeros branch July 19, 2022 18:14
@travisbrown
Copy link
Member

For the record I think accepting non-standard JSON is a mistake (except maybe in some rare cases via a custom parser, but definitely not the default parser).

@zarthross
Copy link
Member

Hey Travis, while I would generally agree with you, this is only impacting the string based json numbers decoding (which I don’t think is in the spec), and not json parsing. I think this change is fine, especially given the stdlib parse methods like BigDecimal.apply accept the leading zeros just fine when handling strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants