gocarina / gocsv

The GoCSV package aims to provide easy CSV serialization and deserialization to the golang programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ParseInt should use base 10 specifically, to avoid crashing on padded numbers

awbacker opened this issue · comments

The default implementation uses base: 0 to autodetect the format based on the string itself. This fails for any zero padded integer greater than 7 :-/

gocsv/types.go

Lines 116 to 126 in b291445

func toInt(in interface{}) (int64, error) {
inValue := reflect.ValueOf(in)
switch inValue.Kind() {
case reflect.String:
s := strings.TrimSpace(inValue.String())
if s == "" {
return 0, nil
}
out := strings.SplitN(s, ".", 2)
return strconv.ParseInt(out[0], 0, 64)

While not strictly incorrect, this is parsing CSV data and not golang source code, and I'd be surpriced if there were 0x007 strings in a csv file that were expected to parse as hex, but base:0 supports it.