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:
dualfroz committed 2026-09-04 22:08:59 +02:00
1 parent d083650302
commit 9bc91ef163
3 files changed
+89 -2

No files matched your search

+4 -2
View File
@@ -130,7 +130,8 @@ 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 a Go literal
return strconv.ParseInt(out[0], 10, 64)
case reflect.Bool:
if inValue.Bool() {
return 1, nil
@@ -164,7 +165,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