-
Notifications
You must be signed in to change notification settings - Fork 277
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
Remove leading 0s before parsing into serde_json::Number
#6766
Remove leading 0s before parsing into serde_json::Number
#6766
Conversation
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: 42b09e789001199f80796a4e |
This comment has been minimized.
This comment has been minimized.
We previously decided to allow leading 0s, per this discussion: #5762 (comment) However, since we use the parsing logic of `serde_json::Number` to produce the internal representation, and that logic fails given leading zeros, we need to normalize the input `&str` a bit before calling `number.parse()`. We already perform some similar normalizations, e.g. ensuring the fractional part is at least a 0 (not empty after the `.`), so there's precedent.
0510cb5
to
7a76bec
Compare
check_parse( | ||
"-00", | ||
LitExpr::Number(serde_json::Number::from_f64(-0.0).unwrap()), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess negative zero has to be a float, since an integer wouldn't be able to represent the negativity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I added a few nits, but feel free to ignore.
apollo-federation/src/sources/connect/json_selection/lit_expr.rs
Outdated
Show resolved
Hide resolved
check_parse( | ||
"-00", | ||
LitExpr::Number(serde_json::Number::from_f64(-0.0).unwrap()), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds right!
We previously decided to allow leading 0s, per this discussion.
However, since we use the parsing logic of
serde_json::Number
to produce the internal representation, and that logic fails given leading zeros, we need to normalize the input&str
a bit before callingnumber.parse()
. We already perform some similar normalizations, e.g. ensuring the fractional part is at least a 0 (not empty after the.
), so there's precedent.Thanks to @nicholascioli for finding this problem using fuzz testing!