Merge pull request #4947 from Azhovan/jabar/allow-path-starting-forward-slash

feat: Allow path starting with slash
This commit is contained in:
Kubernetes Prow Robot
2023-01-17 13:04:33 -08:00
committed by GitHub
2 changed files with 11 additions and 0 deletions

View File

@@ -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

View File

@@ -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"},