app/vminsert/influx: do not allow escaping newline char, since they dont occur in real life

The prefious report with escaped newline chars in influx line protocol was false alarm.
This commit is contained in:
Aliaksandr Valialkin 2019-08-23 18:41:17 +03:00
parent 7fa88c6efc
commit ba7b3806be
2 changed files with 4 additions and 25 deletions

View file

@ -180,7 +180,7 @@ func (f *Field) unmarshal(s string, noEscapeChars, hasQuotedFields bool) error {
func unmarshalRows(dst []Row, s string, tagsPool []Tag, fieldsPool []Field) ([]Row, []Tag, []Field, error) { func unmarshalRows(dst []Row, s string, tagsPool []Tag, fieldsPool []Field) ([]Row, []Tag, []Field, error) {
noEscapeChars := strings.IndexByte(s, '\\') < 0 noEscapeChars := strings.IndexByte(s, '\\') < 0
for len(s) > 0 { for len(s) > 0 {
n := nextUnquotedChar(s, '\n', noEscapeChars, true) n := strings.IndexByte(s, '\n')
if n == 0 { if n == 0 {
// Skip empty line // Skip empty line
s = s[1:] s = s[1:]
@ -291,7 +291,7 @@ func unescapeTagValue(s string, noEscapeChars bool) string {
return string(append(dst, '\\')) return string(append(dst, '\\'))
} }
ch := s[0] ch := s[0]
if ch != ' ' && ch != ',' && ch != '=' && ch != '\\' && ch != '\n' { if ch != ' ' && ch != ',' && ch != '=' && ch != '\\' {
dst = append(dst, '\\') dst = append(dst, '\\')
} }
dst = append(dst, ch) dst = append(dst, ch)

View file

@ -324,11 +324,11 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
}) })
// Escape chars // Escape chars
f(`fo\,bar\=baz,x\==\\a\,\=\q\ \\\a\=\,=4.34`, &Rows{ f(`fo\,bar\=baz,x\=\b=\\a\,\=\q\ \\\a\=\,=4.34`, &Rows{
Rows: []Row{{ Rows: []Row{{
Measurement: `fo,bar=baz`, Measurement: `fo,bar=baz`,
Tags: []Tag{{ Tags: []Tag{{
Key: `x=`, Key: `x=\b`,
Value: `\a,=\q `, Value: `\a,=\q `,
}}, }},
Fields: []Field{{ Fields: []Field{{
@ -338,27 +338,6 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
}}, }},
}) })
// Escape newline
f("fo\\\nb\\,ar,x\\\ny=\\\n\\y a=\"foo\nbar\",b\\\nc\\==34\n", &Rows{
Rows: []Row{{
Measurement: "fo\nb,ar",
Tags: []Tag{{
Key: "x\ny",
Value: "\n\\y",
}},
Fields: []Field{
{
Key: "a",
Value: 0,
},
{
Key: "b\nc=",
Value: 34,
},
},
}},
})
// Multiple lines // Multiple lines
f("foo,tag=xyz field=1.23 48934\n"+ f("foo,tag=xyz field=1.23 48934\n"+
"bar x=-1i\n\n", &Rows{ "bar x=-1i\n\n", &Rows{