Fix access log field parsing

This commit is contained in:
Brendan LE GLAUNEC 2018-10-29 16:24:04 +01:00 committed by Traefiker Bot
parent 450471d30a
commit 993caf5058
2 changed files with 18 additions and 0 deletions

View file

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

View file

@ -301,6 +301,14 @@ func TestFieldsHeadersNamesSet(t *testing.T) {
"X-HEADER-2": "bar", "X-HEADER-2": "bar",
}, },
}, },
{
desc: "Two values separated by space with escaped double quotes should return FieldNames of size 2",
value: "\"X-HEADER-1=foo X-HEADER-2=bar\"",
expected: &FieldHeaderNames{
"X-HEADER-1": "foo",
"X-HEADER-2": "bar",
},
},
} }
for _, test := range testCases { for _, test := range testCases {