-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Quote the numbers even if they are out of range #593
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #593 +/- ##
==========================================
+ Coverage 77.43% 77.47% +0.04%
==========================================
Files 21 21
Lines 7772 7787 +15
==========================================
+ Hits 6018 6033 +15
Misses 1342 1342
Partials 412 412 |
ast/ast.go
Outdated
@@ -342,7 +342,7 @@ func Bool(tk *token.Token) *BoolNode { | |||
// Integer create node for integer value | |||
func Integer(tk *token.Token) *IntegerNode { | |||
var v any | |||
if num := token.ToNumber(tk.Value); num != nil { | |||
if num, _ := token.ToNumber(tk.Value); num != nil { |
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.
This looks odd
Shouldn't it be better and more logic now you refactored to have something like that
if num, _ := token.ToNumber(tk.Value); num != nil { | |
if num, err := token.ToNumber(tk.Value); err == nil { |
With code refactored to return an error when
token/token.go
Outdated
if err != nil { | ||
// Need quotes even when the value is out of range | ||
var numErr *strconv.NumError | ||
if errors.As(err, &numErr) && errors.Is(numErr.Err, strconv.ErrRange) { | ||
return true | ||
} | ||
} |
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.
This is enough
if err != nil { | |
// Need quotes even when the value is out of range | |
var numErr *strconv.NumError | |
if errors.As(err, &numErr) && errors.Is(numErr.Err, strconv.ErrRange) { | |
return true | |
} | |
} | |
// Need quotes even when the value is out of range | |
var numErr *strconv.NumError | |
if errors.As(err, &numErr) && errors.Is(numErr.Err, strconv.ErrRange) { | |
return true | |
} |
token/token.go
Outdated
@@ -538,16 +539,16 @@ type NumberValue struct { | |||
Text string | |||
} | |||
|
|||
func ToNumber(value string) *NumberValue { | |||
func ToNumber(value string) (*NumberValue, error) { |
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.
This change looks like a hammer to fix a scratch.
You are updating the signature of an exported method, it would have consequence.
I would have checked the ErrRange error in this method, and set a boolean variable NeedQuote on the NumberValue struct, then use it in IsQuoteNeeded
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.
Thank you for your comments, @ccoVeille! Hmm, you are right. I haven't thought about the possibility that people use the method, but let me think about it a little more carefully 👍
I’ve migrated most of the logic from |
Thanks |
Closes #586
The
IsNeedQuoted
function previously returnedfalse
when a given string was out of range, asToNumber
failed to parse such strings. I updated theIsNeedQuoted
function to check the error returned byToNumber
and, if it isstrconv.ErrRange
, ensure the string is quoted instead.Before submitting your PR, please confirm the following.