This commit is contained in:
Aliaksandr Valialkin 2024-06-05 03:10:32 +02:00
parent 238115a6e7
commit 827984faa2
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 18 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import (
"math" "math"
"slices" "slices"
"strconv" "strconv"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
"unsafe" "unsafe"
@ -1933,7 +1934,7 @@ func tryParseNumber(s string) (float64, bool) {
if ok { if ok {
return float64(bytes), true return float64(bytes), true
} }
if isNumberPrefix(s) { if isLikelyNumber(s) {
f, err := strconv.ParseFloat(s, 64) f, err := strconv.ParseFloat(s, 64)
if err == nil { if err == nil {
return f, true return f, true
@ -1946,5 +1947,20 @@ func tryParseNumber(s string) (float64, bool) {
return 0, false return 0, false
} }
func isLikelyNumber(s string) bool {
if !isNumberPrefix(s) {
return false
}
if strings.Count(s, ".") > 1 {
// This is likely IP address
return false
}
if strings.IndexByte(s, ':') >= 0 || strings.Count(s, "-") > 2 {
// This is likely a timestamp
return false
}
return true
}
var nan = math.NaN() var nan = math.NaN()
var inf = math.Inf(1) var inf = math.Inf(1)

View file

@ -496,7 +496,7 @@ func TestParseRangeFilter(t *testing.T) {
} }
fr, ok := q.f.(*filterRange) fr, ok := q.f.(*filterRange)
if !ok { if !ok {
t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f) t.Fatalf("unexpected filter type; got %T; want *filterRange; filter: %s", q.f, q.f)
} }
if fr.fieldName != fieldNameExpected { if fr.fieldName != fieldNameExpected {
t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected) t.Fatalf("unexpected fieldName; got %q; want %q", fr.fieldName, fieldNameExpected)