fix: parse integer fields as base 10
toInt and toUint passed base 0 to strconv, which infers the base from the literal the way the Go compiler does. A zero-padded CSV field was then read as octal: 08 and 09 failed with invalid syntax and 010 silently parsed as 8. Pass base 10 at both call sites. Go-style prefixed literals such as 0x1f are no longer accepted; they were undocumented and untested, and cannot be kept without keeping the octal reading of 010 as well. Closes #182
This commit is contained in:
1 parent
0ba11f2f3b
commit
26aafe16a8
3 files changed
+90
-2
No files matched your search
@@ -130,7 +130,9 @@ func toInt(in interface{}) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
out := strings.SplitN(s, ".", 2)
|
||||
return strconv.ParseInt(out[0], 0, 64)
|
||||
// base 10, not 0: a CSV field is data, not Go source, so "010" is ten
|
||||
// and "09" is nine rather than an invalid octal literal
|
||||
return strconv.ParseInt(out[0], 10, 64)
|
||||
case reflect.Bool:
|
||||
if inValue.Bool() {
|
||||
return 1, nil
|
||||
@@ -164,7 +166,8 @@ func toUint(in interface{}) (uint64, error) {
|
||||
}
|
||||
return uint64(f), nil
|
||||
}
|
||||
return strconv.ParseUint(s, 0, 64)
|
||||
// base 10, see toInt
|
||||
return strconv.ParseUint(s, 10, 64)
|
||||
case reflect.Bool:
|
||||
if inValue.Bool() {
|
||||
return 1, nil
|
||||
|
||||
Reference in new issue
Block a user