Skip to content

Commit

Permalink
Merge pull request #4947 from Azhovan/jabar/allow-path-starting-forwa…
Browse files Browse the repository at this point in the history
…rd-slash

feat: Allow path starting with slash
  • Loading branch information
k8s-ci-robot committed Jan 17, 2023
2 parents ec4d1e8 + 368697f commit def01f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kyaml/utils/pathsplitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions kyaml/utils/pathsplitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit def01f0

Please sign in to comment.