diff --git a/Makefile b/Makefile index 90042eec5..72295a246 100644 --- a/Makefile +++ b/Makefile @@ -72,4 +72,4 @@ release_tarball: build check ./create-release-tarball # Go does its own dependency management, outside of make. -.PHONY: build check unit_test regression_test fmt dev +.PHONY: build mlr check unit_test regression_test fmt dev diff --git a/internal/pkg/types/mlrval_infer.go b/internal/pkg/types/mlrval_infer.go index cdbbd6f42..171a6bf06 100644 --- a/internal/pkg/types/mlrval_infer.go +++ b/internal/pkg/types/mlrval_infer.go @@ -5,6 +5,7 @@ package types import ( + "regexp" "strings" "github.com/johnkerl/miller/internal/pkg/lib" @@ -157,23 +158,18 @@ func inferNormally(input string, inferBool bool) *Mlrval { return MlrvalFromString(input) } +var octalDetector = regexp.MustCompile("^-?0[0-9]+") + func inferWithOctalSuppress(input string, inferBool bool) *Mlrval { output := inferNormally(input, inferBool) if output.mvtype != MT_INT && output.mvtype != MT_FLOAT { return output } - if input[0] == '0' && len(input) > 1 { - c := input[1] - if c != 'x' && c != 'X' && c != 'b' && c != 'B' { - return MlrvalFromString(input) - } - } - if strings.HasPrefix(input, "-0") && len(input) > 2 { - c := input[2] - if c != 'x' && c != 'X' && c != 'b' && c != 'B' { - return MlrvalFromString(input) - } + if octalDetector.MatchString(input) { + return MlrvalFromString(input) + } else { + return output } return output diff --git a/test/cases/io-infer-flags/dash-A/expout b/test/cases/io-infer-flags/dash-A/expout index 64ff495d3..2583ff522 100644 --- a/test/cases/io-infer-flags/dash-A/expout +++ b/test/cases/io-infer-flags/dash-A/expout @@ -4,6 +4,10 @@ x t y z 0123 float 84 83.5 07 float 8 7.5 08 float 9 8.5 +0 float 1 0.5 +0. float 1 0.5 +0.0 float 1 0.5 +0.01 float 1.01 0.51 0b0100 float 5 4.5 0x1000 float 4097 4096.5 -123 float -122 -122.5 @@ -13,3 +17,7 @@ x t y z -0x1000 float -4095 -4095.5 -07 float -6 -6.5 -08 float -7 -7.5 +-0 float 1 0.5 +-0. float 1 0.5 +-0.0 float 1 0.5 +-0.01 float 0.99 0.49 diff --git a/test/cases/io-infer-flags/dash-O/expout b/test/cases/io-infer-flags/dash-O/expout index 24a22ab37..4d6ca25d6 100644 --- a/test/cases/io-infer-flags/dash-O/expout +++ b/test/cases/io-infer-flags/dash-O/expout @@ -4,6 +4,10 @@ x t y z 0123 string (error) (error) 07 string (error) (error) 08 string (error) (error) +0 int 1 0.5 +0. float 1 0.5 +0.0 float 1 0.5 +0.01 float 1.01 0.51 0b0100 int 5 4.5 0x1000 int 4097 4096.5 -123 int -122 -122.5 @@ -13,3 +17,7 @@ x t y z -0x1000 int -4095 -4095.5 -07 string (error) (error) -08 string (error) (error) +-0 int 1 0.5 +-0. float 1 0.5 +-0.0 float 1 0.5 +-0.01 float 0.99 0.49 diff --git a/test/cases/io-infer-flags/dash-S/expout b/test/cases/io-infer-flags/dash-S/expout index fc2875e90..9fb9759c9 100644 --- a/test/cases/io-infer-flags/dash-S/expout +++ b/test/cases/io-infer-flags/dash-S/expout @@ -4,6 +4,10 @@ x t y z 0123 string (error) (error) 07 string (error) (error) 08 string (error) (error) +0 string (error) (error) +0. string (error) (error) +0.0 string (error) (error) +0.01 string (error) (error) 0b0100 string (error) (error) 0x1000 string (error) (error) -123 string (error) (error) @@ -13,3 +17,7 @@ x t y z -0x1000 string (error) (error) -07 string (error) (error) -08 string (error) (error) +-0 string (error) (error) +-0. string (error) (error) +-0.0 string (error) (error) +-0.01 string (error) (error) diff --git a/test/cases/io-infer-flags/default/expout b/test/cases/io-infer-flags/default/expout index 94b125761..2ecaa2dab 100644 --- a/test/cases/io-infer-flags/default/expout +++ b/test/cases/io-infer-flags/default/expout @@ -4,6 +4,10 @@ x t y z 0123 int 84 83.5 07 int 8 7.5 08 float 9 8.5 +0 int 1 0.5 +0. float 1 0.5 +0.0 float 1 0.5 +0.01 float 1.01 0.51 0b0100 int 5 4.5 0x1000 int 4097 4096.5 -123 int -122 -122.5 @@ -13,3 +17,7 @@ x t y z -0x1000 int -4095 -4095.5 -07 int -6 -6.5 -08 float -7 -7.5 +-0 int 1 0.5 +-0. float 1 0.5 +-0.0 float 1 0.5 +-0.01 float 0.99 0.49 diff --git a/test/input/infer.csv b/test/input/infer.csv index f1058dda8..fa311ec46 100644 --- a/test/input/infer.csv +++ b/test/input/infer.csv @@ -4,6 +4,10 @@ x 0123 07 08 +0 +0. +0.0 +0.01 0b0100 0x1000 -123 @@ -13,3 +17,7 @@ x -0x1000 -07 -08 +-0 +-0. +-0.0 +-0.01