mlr -O regexp bugfix (#767)

This commit is contained in:
John Kerl 2021-12-03 11:24:19 -05:00 committed by GitHub
parent 7642f7ede6
commit 8e975c9d39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

1 x
4 0123
5 07
6 08
7 0
8 0.
9 0.0
10 0.01
11 0b0100
12 0x1000
13 -123
17 -0x1000
18 -07
19 -08
20 -0
21 -0.
22 -0.0
23 -0.01