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

[String] Cast to INT64 should use base-10 parsing #16

Merged
merged 3 commits into from
Feb 6, 2024

Conversation

ohaibbq
Copy link

@ohaibbq ohaibbq commented Feb 2, 2024

Using base 0 leads to incorrectly parsed integers as well as errors depending on leading-zero format.

goccy#158

return strconv.ParseInt(string(sv), 0, 64)
toParse := string(sv)
base := 0
if !strings.Contains(strings.ToLower(toParse), "0x") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be starts with? I also might be tempted to invert this if so that base 10 is the default and we set 0 inside of the condition

Copy link
Author

@ohaibbq ohaibbq Feb 2, 2024

Choose a reason for hiding this comment

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

-0x00 and +0x00 are valid, so I'm using contains, if its malformed ParseInt will raise an error for the user

@ohaibbq ohaibbq merged commit 377a866 into candidate/rb20240201 Feb 6, 2024
7 checks passed
@ohaibbq ohaibbq deleted the dan/parse-int branch March 28, 2024 18:12
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.

3 participants