Skip to content

Commit

Permalink
Merge pull request #49 from influxdata/rog-033-allow-backslash-n
Browse files Browse the repository at this point in the history
lineprotocol: interpret \n, \r and \t escapes
  • Loading branch information
rogpeppe authored Sep 27, 2021
2 parents 4fadf05 + ea04bea commit e5cb25a
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 119 deletions.
6 changes: 3 additions & 3 deletions lineprotocol/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ const (
var (
fieldSeparatorSpace = newByteSet(" ")
whitespace = fieldSeparatorSpace.union(newByteSet("\r\n"))
tagKeyChars = newByteSet(",= ").union(nonPrintable).invert()
tagKeyChars = newByteSet(",=").union(whitespace).union(nonPrintable).invert()
tagKeyEscapes = newEscaper(",= ")
nonPrintable = newByteSetRange(0, 31).union(newByteSet("\x7f"))
eolChars = newByteSet("\r\n")
measurementChars = newByteSet(", ").union(nonPrintable).invert()
measurementEscapes = newEscaper(" ,")
tagValChars = newByteSet(",=").union(whitespace).invert()
tagValChars = newByteSet(",=").union(whitespace).union(nonPrintable).invert()
tagValEscapes = newEscaper(", =")
fieldKeyChars = tagKeyChars
fieldKeyEscapes = tagKeyEscapes
fieldStringValChars = newByteSet(`"`).invert()
fieldStringValEscapes = newEscaper(`\"`)
fieldStringValEscapes = newEscaper("\\\"\n\r\t")
fieldValChars = newByteSet(",").union(whitespace).invert()
timeChars = newByteSet("-0123456789")
commentChars = nonPrintable.invert().without(eolChars)
Expand Down
63 changes: 63 additions & 0 deletions lineprotocol/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,69 @@ next x=1`,
Error: `at line ∑¹: expected closing quote for string field value, found end of input`,
}},
}},
}, {
testName: "non-printable-ASCII-in-tag-key",
text: "m foo∑¹\x01=bar x=1",
expect: []Point{{
Measurement: "m",
Fields: []FieldKeyValue{{
Error: `at line ∑¹: want '=' after field key "foo", found '\x01'`,
}},
}},
}, {
testName: "non-printable-ASCII-in-tag-key",
text: "m,∑¹foo\x03=bar x=1",
expect: []Point{{
Measurement: "m",
Tags: []TagKeyValue{{
Error: `at line ∑¹: expected '=' after tag key "foo", but got '\x03' instead`,
}},
}},
}, {
testName: "non-printable-ASCII-in-tag-value",
text: "m,foo=bar∑¹\x02 x=1",
expect: []Point{{
Measurement: "m",
Tags: []TagKeyValue{{
Key: "foo",
Value: "bar",
}, {
Error: `at line ∑¹: expected tag key or field but found '\x02' instead`,
}},
}},
}, {
testName: "non-printable-ASCII-in-field-key",
text: "m foo∑¹\x01=bar",
expect: []Point{{
Measurement: "m",
Fields: []FieldKeyValue{{
Error: `at line ∑¹: want '=' after field key "foo", found '\x01'`,
}},
}},
}, {
testName: "backslash-escapes-in-string-field",
text: `m s="\t\r\n\v"`,
expect: []Point{{
Measurement: "m",
Fields: []FieldKeyValue{{
Key: "s",
Value: "\t\r\n\\v",
}},
}},
}, {
testName: "backslash-escapes-in-tags",
text: `m,s=\t\r\n\v x=1`,
expect: []Point{{
Measurement: "m",
Tags: []TagKeyValue{{
Key: "s",
Value: `\t\r\n\v`,
}},
Fields: []FieldKeyValue{{
Key: "x",
Value: 1.0,
}},
}},
}}

func TestDecoder(t *testing.T) {
Expand Down
Loading

0 comments on commit e5cb25a

Please sign in to comment.