Description
Component(s)
pkg/stanza
What happened?
Description
The Stanza key value parser does not respect quotes while doing pair parsing with a custom pair delimiter.
Steps to Reproduce
Perhaps easiest to reproduce by adding the following unit test to the TestParser
unit test in this test file:
{
"custom pair delimiter in quoted value",
func(kv *Config) {
kv.PairDelimiter = "_"
},
&entry.Entry{
Body: `a=b_c="d_e"`,
},
&entry.Entry{
Attributes: map[string]any{
"a": "b",
"c": "d_e",
},
Body: `a=b_c="d_e"`,
},
false,
false,
},
Expected Result
In the unit test above, we set a custom pair delimiter of _
and provide an input string that has a quoted value which contains the pair delimiter (c="d_e"
). I would expect the parser to respect the quotes and split the input string into 2 key value pairs (a=b
, c="d_e"
). Then the parser would split the pairs into their keys and values resulting in the Attributes
map defined in the unit test.
Actual Result
The actual result is during pair parsing the parser does not respect quotes and splits on the quoted _
. This means that pair parsing results in these values: a=b
, c="d
, e"
. When the parser then tries to split the keys and values in each pair, it fails on e"
because there is no delimiter to split on. The resulting output of the test case is
Error: Received unexpected error: expected 'e"' to split by '=' into two items, got 1
Collector version
main (present in current commit 292f291)
Environment information
Environment
Don't believe this is necessary
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
I found this bug while adopting the parser over for a new OTTL function discussed in this issue: #30998. This bug occurs when a custom pair delimiter is used becausestrings.Split()
gets used to split up the pairs, which does not respect quotes. This bug doesn't occur when using the default pair delimiter (white space) because a custom function passed to strings.FieldsFunc
is used which does respect quotes.