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

Fix Conversion of String Values with Leading Zeros #223

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions caste.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func ToInt64E(i interface{}) (int64, error) {
case float32:
return int64(s), nil
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
return v, nil
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func ToInt32E(i interface{}) (int32, error) {
case float32:
return int32(s), nil
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
return int32(v), nil
}
Expand Down Expand Up @@ -400,7 +400,7 @@ func ToInt16E(i interface{}) (int16, error) {
case float32:
return int16(s), nil
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
return int16(v), nil
}
Expand Down Expand Up @@ -452,7 +452,7 @@ func ToInt8E(i interface{}) (int8, error) {
case float32:
return int8(s), nil
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
return int8(v), nil
}
Expand Down Expand Up @@ -504,7 +504,7 @@ func ToIntE(i interface{}) (int, error) {
case float32:
return int(s), nil
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
return int(v), nil
}
Expand Down Expand Up @@ -537,7 +537,7 @@ func ToUintE(i interface{}) (uint, error) {

switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
Expand Down Expand Up @@ -613,7 +613,7 @@ func ToUint64E(i interface{}) (uint64, error) {

switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
Expand Down Expand Up @@ -689,7 +689,7 @@ func ToUint32E(i interface{}) (uint32, error) {

switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
Expand Down Expand Up @@ -765,7 +765,7 @@ func ToUint16E(i interface{}) (uint16, error) {

switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
Expand Down Expand Up @@ -841,7 +841,7 @@ func ToUint8E(i interface{}) (uint8, error) {

switch s := i.(type) {
case string:
v, err := strconv.ParseInt(trimZeroDecimal(s), 0, 0)
v, err := strconv.ParseInt(trimZeroDecimal(s), 10, 0)
if err == nil {
if v < 0 {
return 0, errNegativeNotAllowed
Expand Down Expand Up @@ -911,6 +911,7 @@ func indirect(a interface{}) interface{} {
if a == nil {
return nil
}

if t := reflect.TypeOf(a); t.Kind() != reflect.Ptr {
// Avoid creating a reflect.Value if it's not a pointer.
return a
Expand Down