Skip to content

Commit 993caf5

Browse files
Ullaakuttraefiker
authored andcommitted
Fix access log field parsing
1 parent 450471d commit 993caf5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

types/logs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func (f *FieldNames) Get() interface{} {
8888
// Set's argument is a string to be parsed to set the flag.
8989
// It's a space-separated list, so we split it.
9090
func (f *FieldNames) Set(value string) error {
91+
// When arguments are passed through YAML, escaped double quotes
92+
// might be added to this string, and they would break the last
93+
// key/value pair. This ensures the string is clean.
94+
value = strings.Trim(value, "\"")
95+
9196
fields := strings.Fields(value)
9297

9398
for _, field := range fields {
@@ -123,6 +128,11 @@ func (f *FieldHeaderNames) Get() interface{} {
123128
// Set's argument is a string to be parsed to set the flag.
124129
// It's a space-separated list, so we split it.
125130
func (f *FieldHeaderNames) Set(value string) error {
131+
// When arguments are passed through YAML, escaped double quotes
132+
// might be added to this string, and they would break the last
133+
// key/value pair. This ensures the string is clean.
134+
value = strings.Trim(value, "\"")
135+
126136
fields := strings.Fields(value)
127137

128138
for _, field := range fields {

types/logs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ func TestFieldsHeadersNamesSet(t *testing.T) {
301301
"X-HEADER-2": "bar",
302302
},
303303
},
304+
{
305+
desc: "Two values separated by space with escaped double quotes should return FieldNames of size 2",
306+
value: "\"X-HEADER-1=foo X-HEADER-2=bar\"",
307+
expected: &FieldHeaderNames{
308+
"X-HEADER-1": "foo",
309+
"X-HEADER-2": "bar",
310+
},
311+
},
304312
}
305313

306314
for _, test := range testCases {

0 commit comments

Comments
 (0)