skip empty string for start position

pull/4596/head
ch33hau 2015-10-28 22:12:53 +08:00
parent d8e4655e0f
commit f13af15e71
2 changed files with 24 additions and 1 deletions

View File

@ -726,7 +726,7 @@ func skipWhitespace(buf []byte, i int) int {
return i
}
if buf[i] == ' ' || buf[i] == '\t' {
if buf[i] == ' ' || buf[i] == '\t' || buf[i] == 0 {
i += 1
continue
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"math"
"math/rand"
"reflect"
"strconv"
"strings"
@ -1509,3 +1510,25 @@ func TestPrecisionString(t *testing.T) {
}
}
}
func TestParsePointsStringWithExtraBuffer(t *testing.T) {
b := make([]byte, 70*5000)
buf := bytes.NewBuffer(b)
key := "cpu,host=A,region=uswest"
buf.WriteString(fmt.Sprintf("%s value=%.3f 1\n", key, rand.Float64()))
points, err := models.ParsePointsString(buf.String())
if err != nil {
t.Fatalf("failed to write points: %s", err.Error())
}
pointKey := string(points[0].Key())
if len(key) != len(pointKey) {
t.Fatalf("expected length of both keys are same but got %d and %d", len(key), len(pointKey))
}
if key != pointKey {
t.Fatalf("expected both keys are same but got %s and %s", key, pointKey)
}
}