-
Notifications
You must be signed in to change notification settings - Fork 344
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
Unmarshall numbers in options to number not float64 #308
Unmarshall numbers in options to number not float64 #308
Conversation
Signed-off-by: Pavol Loffay <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #308 +/- ##
==========================================
+ Coverage 88.64% 88.68% +0.04%
==========================================
Files 70 70
Lines 3143 3156 +13
==========================================
+ Hits 2786 2799 +13
Misses 244 244
Partials 113 113
Continue to review full report at Codecov.
|
@@ -38,7 +39,11 @@ func (o *Options) Filter(prefix string) Options { | |||
// UnmarshalJSON implements an alternative parser for this field | |||
func (o *Options) UnmarshalJSON(b []byte) error { | |||
var entries map[string]interface{} | |||
json.Unmarshal(b, &entries) | |||
d := json.NewDecoder(bytes.NewReader(b)) | |||
d.UseNumber() |
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.
A bit of context: JSON spec defines numbers as float64
so all number are by default unmarshalled to float64
. Our Options.Args()
method uses fmt.Sprintf(%v, val)
to convert the value to string - the %v
formats the float into exponent notation e.g. 5e+06
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.
Thanks for the details - would it be possible to provide a test?
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.
Including one that fails the decode, just to improve the code coverage.
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.
Apart from it is it ok?
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.
Yes
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Resolves #302
Signed-off-by: Pavol Loffay [email protected]