diff --git a/models/points.go b/models/points.go index 277748679d..6425f911dd 100644 --- a/models/points.go +++ b/models/points.go @@ -614,14 +614,11 @@ func scanNumber(buf []byte, i int) (int, error) { continue } - // NaN is a valid float + // NaN is an unsupported value if i+2 < len(buf) && (buf[i] == 'N' || buf[i] == 'n') { - if (buf[i+1] == 'a' || buf[i+1] == 'A') && (buf[i+2] == 'N' || buf[i+2] == 'n') { - i += 3 - continue - } return i, fmt.Errorf("invalid number") } + if !isNumeric(buf[i]) { return i, fmt.Errorf("invalid number") } diff --git a/models/points_test.go b/models/points_test.go index c6b7f08d9b..970ec07abc 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -1097,36 +1097,21 @@ func TestNewPointLargeInteger(t *testing.T) { ) } -func TestNewPointNaN(t *testing.T) { - test(t, `cpu value=NaN 1000000000`, - models.NewPoint( - "cpu", - models.Tags{}, - models.Fields{ - "value": math.NaN(), - }, - time.Unix(1, 0)), - ) +func TestParsePointNaN(t *testing.T) { + _, err := models.ParsePointsString("cpu value=NaN 1000000000") + if err == nil { + t.Fatalf("ParsePoints expected error, got nil") + } - test(t, `cpu value=nAn 1000000000`, - models.NewPoint( - "cpu", - models.Tags{}, - models.Fields{ - "value": math.NaN(), - }, - time.Unix(1, 0)), - ) + _, err = models.ParsePointsString("cpu value=nAn 1000000000") + if err == nil { + t.Fatalf("ParsePoints expected error, got nil") + } - test(t, `nan value=NaN`, - models.NewPoint( - "nan", - models.Tags{}, - models.Fields{ - "value": math.NaN(), - }, - time.Unix(0, 0)), - ) + _, err = models.ParsePointsString("cpu value=NaN") + if err == nil { + t.Fatalf("ParsePoints expected error, got nil") + } } func TestNewPointLargeNumberOfTags(t *testing.T) {