Fix handling of escapes within fieldset (#3003)
Line protocol does not require or allow escaping of backslash, the only requirement for a byte to be escaped is if it is an escapable char and preceeded immediately by a slash.
This commit is contained in:
parent
05309855e3
commit
4780073ba1
|
@ -98,7 +98,7 @@ func indexUnescapedByte(buf []byte, b byte) int {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
keyi += i
|
keyi += i
|
||||||
if countBackslashes(buf, keyi-1)%2 == 0 {
|
if buf[keyi-1] != '\\' {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
keyi++
|
keyi++
|
||||||
|
@ -107,24 +107,6 @@ func indexUnescapedByte(buf []byte, b byte) int {
|
||||||
return keyi
|
return keyi
|
||||||
}
|
}
|
||||||
|
|
||||||
// countBackslashes counts the number of preceding backslashes starting at
|
|
||||||
// the 'start' index.
|
|
||||||
func countBackslashes(buf []byte, index int) int {
|
|
||||||
var count int
|
|
||||||
for {
|
|
||||||
if index < 0 {
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
if buf[index] == '\\' {
|
|
||||||
count++
|
|
||||||
index--
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
type metric struct {
|
type metric struct {
|
||||||
name []byte
|
name []byte
|
||||||
tags []byte
|
tags []byte
|
||||||
|
|
|
@ -255,6 +255,8 @@ func TestNewMetric_Fields(t *testing.T) {
|
||||||
"bool": true,
|
"bool": true,
|
||||||
"false": false,
|
"false": false,
|
||||||
"string": "test",
|
"string": "test",
|
||||||
|
"quote_string": `x"y`,
|
||||||
|
"backslash_quote_string": `x\"y`,
|
||||||
}
|
}
|
||||||
m, err := New("cpu", tags, fields, now)
|
m, err := New("cpu", tags, fields, now)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -367,7 +369,7 @@ func TestIndexUnescapedByte(t *testing.T) {
|
||||||
{
|
{
|
||||||
in: []byte(`foo\\bar`),
|
in: []byte(`foo\\bar`),
|
||||||
b: 'b',
|
b: 'b',
|
||||||
expected: 5,
|
expected: -1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: []byte(`foobar`),
|
in: []byte(`foobar`),
|
||||||
|
|
Loading…
Reference in New Issue