fix(models): fix the line breaker

pull/17361/head
Kelvin Wang 2020-03-19 17:50:41 -04:00
parent e7c363e60d
commit 60a3922446
2 changed files with 18 additions and 1 deletions

View File

@ -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]
}

View File

@ -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 {