feat: Allow paths starting with slash

This commit is contained in:
Jabar Asadi
2022-12-26 17:14:26 +01:00
parent aec35009ed
commit 368697f8ef
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"},