diff --git a/go.mod b/go.mod index 5f2930f8c..3d673bf53 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/traefik/traefik/v2 go 1.17 require ( - github.com/BurntSushi/toml v1.0.0 + github.com/BurntSushi/toml v1.1.0 github.com/ExpediaDotCom/haystack-client-go v0.0.0-20190315171017-e7edbdf53a61 github.com/Masterminds/sprig/v3 v3.2.2 github.com/abbot/go-http-auth v0.0.0-00010101000000-000000000000 @@ -53,9 +53,9 @@ require ( github.com/prometheus/client_model v0.2.0 github.com/rancher/go-rancher-metadata v0.0.0-20200311180630-7f4c936a06ac github.com/sirupsen/logrus v1.8.1 - github.com/stretchr/testify v1.7.5 + github.com/stretchr/testify v1.8.0 github.com/stvp/go-udp-testing v0.0.0-20191102171040-06b61409b154 - github.com/traefik/paerser v0.1.5 + github.com/traefik/paerser v0.1.6 github.com/traefik/yaegi v0.13.0 github.com/uber/jaeger-client-go v2.30.0+incompatible github.com/uber/jaeger-lib v2.2.0+incompatible diff --git a/go.sum b/go.sum index 2eecd9497..dc90e2ccb 100644 --- a/go.sum +++ b/go.sum @@ -114,8 +114,8 @@ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbt github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= -github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 h1:3nVO1nQyh64IUY6BPZUpMYMZ738Pu+LsMt3E0eqqIYw= github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583/go.mod h1:EP9f4GqaDJyP1F5jTNMtzdIpw3JpNs3rMSJOnYywCiw= @@ -1864,8 +1864,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stvp/go-udp-testing v0.0.0-20191102171040-06b61409b154 h1:XGopsea1Dw7ecQ8JscCNQXDGYAKDiWjDeXnpN/+BY9g= github.com/stvp/go-udp-testing v0.0.0-20191102171040-06b61409b154/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= @@ -1909,8 +1910,8 @@ github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea h1:SXhTLE6pb6eld/ github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea/go.mod h1:WPnis/6cRcDZSUvVmezrxJPkiO87ThFYsoUiMwWNDJk= github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305 h1:y/1cL5AL2oRcfzz8CAHHhR6kDDfIOT0WEyH5k40sccM= github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305/go.mod h1:gXOLibKqQTRAVuVZ9gX7G9Ykky8ll8yb4slxsEMoY0c= -github.com/traefik/paerser v0.1.5 h1:crit7KzQ9PUWGCYu+H2acwyr7ZKb3RQDSn6iJCtxBhE= -github.com/traefik/paerser v0.1.5/go.mod h1:Fuwl9DWJfGpZPPwZY6djYIF0vhvzhLmCizn6P66UeLY= +github.com/traefik/paerser v0.1.6 h1:UqqAW0M3r+aF7DibUVwO1PiZ8cXLsUkpFv5hhxPCscA= +github.com/traefik/paerser v0.1.6/go.mod h1:Dk3Bfz6Zyj13/S8pJyRdx/FNvXlsVRVbtp0UK4ZSiA0= github.com/traefik/yaegi v0.13.0 h1:dNwyGNSLHuRw5xswpbuW1TlzzGDciiK6uAighR1tMsc= github.com/traefik/yaegi v0.13.0/go.mod h1:RuCwD8/wsX7b6KoQHOaIFUfuH3gQIK4KWnFFmJMw5VA= github.com/transip/gotransip/v6 v6.6.1 h1:nsCU1ErZS5G0FeOpgGXc4FsWvBff9GPswSMggsC4564= diff --git a/pkg/plugins/middlewares.go b/pkg/plugins/middlewares.go index 8e476cce3..09edbc954 100644 --- a/pkg/plugins/middlewares.go +++ b/pkg/plugins/middlewares.go @@ -86,7 +86,7 @@ func (p middlewareBuilder) createConfig(config map[string]interface{}) (reflect. vConfig := results[0] cfg := &mapstructure.DecoderConfig{ - DecodeHook: stringToSliceHookFunc, + DecodeHook: mapstructure.StringToSliceHookFunc(","), WeaklyTypedInput: true, Result: vConfig.Interface(), } diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index 63b513ae8..fdfb9fbce 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "reflect" "strings" "github.com/hashicorp/go-multierror" @@ -167,26 +166,3 @@ func checkLocalPluginManifest(descriptor LocalDescriptor) error { return errs.ErrorOrNil() } - -func stringToSliceHookFunc(f reflect.Kind, t reflect.Kind, data interface{}) (interface{}, error) { - if f != reflect.String || t != reflect.Slice { - return data, nil - } - - raw := data.(string) - if raw == "" { - return []string{}, nil - } - - if strings.Contains(raw, "║") { - values := strings.Split(raw, "║") - // Removes the first value if the slice has a length of 2 and a first value empty. - // It's a workaround to escape the parsing on `,`. - if len(values) == 2 && values[0] == "" { - return values[1:], nil - } - return values, nil - } - - return strings.Split(raw, ","), nil -} diff --git a/pkg/plugins/plugins_test.go b/pkg/plugins/plugins_test.go deleted file mode 100644 index 57d3d3235..000000000 --- a/pkg/plugins/plugins_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package plugins - -import ( - "reflect" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func Test_stringToSliceHookFunc(t *testing.T) { - testCases := []struct { - desc string - data string - expected []string - }{ - { - desc: "without separator", - data: "abc", - expected: []string{"abc"}, - }, - { - desc: "with the file separator", - data: "a║b║c", - expected: []string{"a", "b", "c"}, - }, - { - desc: "with the label separator", - data: "a,b,c", - expected: []string{"a", "b", "c"}, - }, - { - desc: "with the file separator and values with commas", - data: "a,z║b,w║c,x,y", - expected: []string{"a,z", "b,w", "c,x,y"}, - }, - { - desc: "escaping workaround", - data: "║a,z", - expected: []string{"a,z"}, - }, - { - desc: "with the file separator and empty item", - data: "║a║z", - expected: []string{"", "a", "z"}, - }, - } - - for _, test := range testCases { - test := test - t.Run(test.desc, func(t *testing.T) { - t.Parallel() - - values, err := stringToSliceHookFunc(reflect.String, reflect.Slice, test.data) - require.NoError(t, err) - - assert.EqualValues(t, test.expected, values) - }) - } -} diff --git a/pkg/plugins/providers.go b/pkg/plugins/providers.go index ac9aa296f..abec8d1b8 100644 --- a/pkg/plugins/providers.go +++ b/pkg/plugins/providers.go @@ -93,7 +93,7 @@ func newProvider(builder providerBuilder, config map[string]interface{}, provide } cfg := &mapstructure.DecoderConfig{ - DecodeHook: stringToSliceHookFunc, + DecodeHook: mapstructure.StringToSliceHookFunc(","), WeaklyTypedInput: true, Result: vConfig.Interface(), }