From 368697f8ef43eed5da813cb80dab9f3da2d5cf31 Mon Sep 17 00:00:00 2001 From: Jabar Asadi Date: Mon, 26 Dec 2022 17:14:26 +0100 Subject: [PATCH] feat: Allow paths starting with slash --- kyaml/utils/pathsplitter.go | 7 +++++++ kyaml/utils/pathsplitter_test.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/kyaml/utils/pathsplitter.go b/kyaml/utils/pathsplitter.go index aa560299f..6ce1f899d 100644 --- a/kyaml/utils/pathsplitter.go +++ b/kyaml/utils/pathsplitter.go @@ -11,6 +11,13 @@ import "strings" func PathSplitter(path string, delimiter string) []string { ps := strings.Split(path, delimiter) var res []string + + // allow path to start with forward slash + // i.e. /a/b/c + if len(ps) > 1 && ps[0] == "" { + ps = ps[1:] + } + res = append(res, ps[0]) for i := 1; i < len(ps); i++ { last := len(res) - 1 diff --git a/kyaml/utils/pathsplitter_test.go b/kyaml/utils/pathsplitter_test.go index 180f3e259..6878c582a 100644 --- a/kyaml/utils/pathsplitter_test.go +++ b/kyaml/utils/pathsplitter_test.go @@ -27,6 +27,10 @@ func TestPathSplitter(t *testing.T) { path: "a/b/c", exp: []string{"a", "b", "c"}, }, + { + path: "/a/b/c", + exp: []string{"a", "b", "c"}, + }, { path: `a/b[]/c`, exp: []string{"a", "b[]", "c"},