Skip to content

fix: fallback to decimal for integer strings with leading zeros - #362

Open
wwww-deeeee wants to merge 1 commit into
spf13:masterfrom
wwww-deeeee:fix-issue147-leading-zeros
Open

wwww-deeeee wants to merge 1 commit into
spf13:masterfrom
wwww-deeeee:fix-issue147-leading-zeros

Conversation

@wwww-deeeee

Copy link
Copy Markdown

When parsing integer strings with leading zeros (e.g. '08', '09', '-08'), strconv.ParseInt with base 0 treats them as octal numbers, which fails due to digits 8 and 9 being invalid in base 8.

This change adds a fallback to base 10 when base 0 parsing fails, allowing common business decimal values like months or dates with leading zeros to be parsed correctly while preserving support for 0x, 0b, and valid octal numbers.

Closes #147

When parsing integer strings with leading zeros (e.g. '08', '09', '-08'), strconv.ParseInt with base 0 treats them as octal numbers, which fails due to digits 8 and 9 being invalid in base 8.

This change adds a fallback to base 10 when base 0 parsing fails, allowing common business decimal values like months or dates with leading zeros to be parsed correctly while preserving support for 0x, 0b, and valid octal numbers.

Closes spf13#147

Signed-off-by: wwww-deeeee <192517353+wwww-deeeee@users.noreply.github.com>
@CLAassistant

CLAassistant commented Sep 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

cast.ToInt("08") returned 0

2 participants