Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
SDI-2101:issue1273 Fixed the parseNamespace to allow arbitary separators
Browse files Browse the repository at this point in the history
  • Loading branch information
candysmurf committed Oct 13, 2016
1 parent d6569e6 commit 85b60c9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mgmt/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,17 @@ func respond(code int, b rbody.Body, w http.ResponseWriter) {
}

func parseNamespace(ns string) []string {
if strings.Index(ns, "/") == 0 {
ns = ns[1:]
}
if ns[len(ns)-1] == '/' {
ns = ns[:len(ns)-1]
fc := getFirstChar(ns)
ns = strings.Trim(ns, fc)
return strings.Split(ns, fc)
}

// GetFirstChar returns the first character from the input string.
func getFirstChar(s string) string {
firstChar := ""
for _, r := range s {
firstChar = fmt.Sprintf("%c", r)
break
}
return strings.Split(ns, "/")
return firstChar
}
41 changes: 41 additions & 0 deletions mgmt/rest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,44 @@ func TestRestAPIDefaultConfig(t *testing.T) {
})
})
}

func TestParseNamespace(t *testing.T) {
tcs := getNsTestCases()

Convey("Test parseNamespace", t, func() {
for _, c := range tcs {
Convey("Test parseNamespace "+c.input, func() {
So(c.output, ShouldResemble, parseNamespace(c.input))
})
}
})
}

type nsTestCase struct {
input string
output []string
}

func getNsTestCases() []nsTestCase {
tcs := []nsTestCase{
{
input: "小a小b小c",
output: []string{"a", "b", "c"}},
{
input: "%a%b%c",
output: []string{"a", "b", "c"}},
{
input: "-aヒ-b/-c|",
output: []string{"aヒ", "b/", "c|"}},
{
input: ">a>b=>c=",
output: []string{"a", "b=", "c="}},
{
input: ">a>b<>c<",
output: []string{"a", "b<", "c<"}},
{
input: "㊽a㊽b%㊽c/|",
output: []string{"a", "b%", "c/|"}},
}
return tcs
}

0 comments on commit 85b60c9

Please sign in to comment.