Skip to content

Commit

Permalink
Merge pull request #17361 from influxdata/cli_batch_writer
Browse files Browse the repository at this point in the history
fix(models): fix the line breaker
  • Loading branch information
kelwang authored Mar 19, 2020
2 parents 593ba05 + 60a3922 commit b7e7de3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion models/points_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (pp *pointsParser) parsePoints(buf []byte) (err error) {
}

// strip the newline if one is present
if block[len(block)-1] == '\n' {
if lb := block[len(block)-1]; lb == '\n' || lb == '\r' {
block = block[:len(block)-1]
}

Expand Down
17 changes: 17 additions & 0 deletions models/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,23 @@ func TestParsePointFloatMultipleDecimals(t *testing.T) {
}
}

func TestParseWithLineBreaks(t *testing.T) {
ss := []string{
"cpu,host=serverA,region=us-west value=1i\ncpu,host=serverA,region=us-west value=2i",
"cpu,host=serverA,region=us-west value=1i\n\ncpu,host=serverA,region=us-west value=2i",
"cpu,host=serverA,region=us-west value=1i\r\ncpu,host=serverA,region=us-west value=2i",
}
for _, s := range ss {
pp, err := models.ParsePointsString(s, "mm")
if err != nil {
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, s, err)
}
if l := len(pp); l != 2 {
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp 2`, s, l)
}
}
}

func TestParsePointInteger(t *testing.T) {
_, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=1i`, "mm")
if err != nil {
Expand Down

0 comments on commit b7e7de3

Please sign in to comment.