Skip to content

Commit

Permalink
skip empty string for start position
Browse files Browse the repository at this point in the history
  • Loading branch information
ch33hau committed Oct 28, 2015
1 parent d8e4655 commit f13af15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion models/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions models/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"math"
"math/rand"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit f13af15

Please sign in to comment.