From ef9b79f85c16bc745bfd034ccc7c31f9f66f5a28 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Doumenjou <925513+jbdoumenjou@users.noreply.github.com> Date: Thu, 5 Aug 2021 18:02:12 +0200 Subject: [PATCH] Remove unwanted trailing slash in key Co-authored-by: Mathieu Lonjaret --- pkg/config/kv/kv_node.go | 2 +- pkg/config/kv/kv_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/config/kv/kv_node.go b/pkg/config/kv/kv_node.go index ef1571c1e..229525ef6 100644 --- a/pkg/config/kv/kv_node.go +++ b/pkg/config/kv/kv_node.go @@ -24,7 +24,7 @@ func DecodeToNode(pairs []*store.KVPair, rootName string, filters ...string) (*p return nil, fmt.Errorf("invalid label root %s", rootName) } - split := strings.Split(pair.Key[len(rootName)+1:], "/") + split := strings.FieldsFunc(pair.Key[len(rootName)+1:], func(c rune) bool { return c == '/' }) parts := []string{rootName} for _, fragment := range split { diff --git a/pkg/config/kv/kv_test.go b/pkg/config/kv/kv_test.go index c94da1bce..f7c0d7ed9 100644 --- a/pkg/config/kv/kv_test.go +++ b/pkg/config/kv/kv_test.go @@ -28,6 +28,7 @@ func TestDecode(t *testing.T) { "traefik/fieldf/Test2": "B", "traefik/fieldg/0/name": "A", "traefik/fieldg/1/name": "B", + "traefik/fieldh/": "foo", }, expected: &sample{ FieldA: "bar", @@ -45,6 +46,7 @@ func TestDecode(t *testing.T) { {Name: "A"}, {Name: "B"}, }, + FieldH: "foo", }, }, { @@ -61,6 +63,7 @@ func TestDecode(t *testing.T) { "foo/bar/traefik/fieldf/Test2": "B", "foo/bar/traefik/fieldg/0/name": "A", "foo/bar/traefik/fieldg/1/name": "B", + "foo/bar/traefik/fieldh/": "foo", }, expected: &sample{ FieldA: "bar", @@ -78,6 +81,7 @@ func TestDecode(t *testing.T) { {Name: "A"}, {Name: "B"}, }, + FieldH: "foo", }, }, } @@ -107,6 +111,7 @@ type sample struct { } `label:"allowEmpty"` FieldF map[string]string FieldG []sub + FieldH string } type sub struct {