Casting a string to int with a 0 in prefix does not work as expected
Open
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4k
- Forks
- 337
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
When I cast a string with prefixed 0 like "0123" with cast.ToInt("0123"), it results into 83 instead of the expected 123
Example code:
package main
import (
"fmt"
"github.com/spf13/cast"
)
func main() {
numb := "0123"
castedNumb := cast.ToInt(t)
fmt.Println(numb, castedNumb)
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported behavior through the cast.ToInt entry point using the "0123" example, then inspect the conversion path it uses for numeric strings. Done means the conversion returns 123 rather than 83 while preserving the expected behavior for other supported integer inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100