mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
feat: Allow paths starting with slash
This commit is contained in:
@@ -11,6 +11,13 @@ import "strings"
|
|||||||
func PathSplitter(path string, delimiter string) []string {
|
func PathSplitter(path string, delimiter string) []string {
|
||||||
ps := strings.Split(path, delimiter)
|
ps := strings.Split(path, delimiter)
|
||||||
var res []string
|
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])
|
res = append(res, ps[0])
|
||||||
for i := 1; i < len(ps); i++ {
|
for i := 1; i < len(ps); i++ {
|
||||||
last := len(res) - 1
|
last := len(res) - 1
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ func TestPathSplitter(t *testing.T) {
|
|||||||
path: "a/b/c",
|
path: "a/b/c",
|
||||||
exp: []string{"a", "b", "c"},
|
exp: []string{"a", "b", "c"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/a/b/c",
|
||||||
|
exp: []string{"a", "b", "c"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: `a/b[]/c`,
|
path: `a/b[]/c`,
|
||||||
exp: []string{"a", "b[]", "c"},
|
exp: []string{"a", "b[]", "c"},
|
||||||
|
|||||||
Reference in New Issue
Block a user