Skip to content

fix: parse bare hex strings as uint64#347

Open
leno23 wants to merge 1 commit into
spf13:masterfrom
leno23:fix/hex-string-uint64-334
Open

fix: parse bare hex strings as uint64#347
leno23 wants to merge 1 commit into
spf13:masterfrom
leno23:fix/hex-string-uint64-334

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 26, 2026

Summary

Fixes #334

ToUint64 / ToUint64E now accept bare hexadecimal strings (without a 0x prefix) when the string contains hex digits including at least one letter a-f/A-F.

Example:

cast.ToUint64("882d5422d5fffff") // 613286979481632767

Approach

  • After strconv.ParseUint(s, 0, 0) fails, retry with base 16 when the string looks like hex.
  • Pure decimal strings that fail for other reasons (overflow, invalid chars) are unchanged.

Test plan

  • go test ./...
  • Added TestIssue334_HexStringToUint64

Made with Cursor

Fixes spf13#334

When ParseUint with base 0 fails, retry with base 16 if the string
looks like a hexadecimal value (contains a-f/A-F).

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


wuyangfan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Feature: Add hex string to uint64 conversion support

2 participants