Skip to content
Snippets Groups Projects
Commit b4b459e9 authored by Rohith's avatar Rohith
Browse files

Resource Slashs

- we should inform the user that a prefix slash is required, rather than pemitting the error
parent 34621eb0
Branches
Tags
No related merge requests found
...@@ -33,7 +33,6 @@ func (r *Resource) parse(resource string) (*Resource, error) { ...@@ -33,7 +33,6 @@ func (r *Resource) parse(resource string) (*Resource, error) {
if resource == "" { if resource == "" {
return nil, errors.New("the resource has no options") return nil, errors.New("the resource has no options")
} }
// parse the syntax
for _, x := range strings.Split(resource, "|") { for _, x := range strings.Split(resource, "|") {
kp := strings.Split(x, "=") kp := strings.Split(x, "=")
if len(kp) != 2 { if len(kp) != 2 {
...@@ -42,6 +41,9 @@ func (r *Resource) parse(resource string) (*Resource, error) { ...@@ -42,6 +41,9 @@ func (r *Resource) parse(resource string) (*Resource, error) {
switch kp[0] { switch kp[0] {
case "uri": case "uri":
r.URL = kp[1] r.URL = kp[1]
if !strings.HasPrefix(r.URL, "/") {
return nil, errors.New("the resource uri should start with a '/'")
}
case "methods": case "methods":
r.Methods = strings.Split(kp[1], ",") r.Methods = strings.Split(kp[1], ",")
if len(r.Methods) == 1 { if len(r.Methods) == 1 {
......
...@@ -29,6 +29,7 @@ func TestDecodeResourceBad(t *testing.T) { ...@@ -29,6 +29,7 @@ func TestDecodeResourceBad(t *testing.T) {
{Option: "unknown=bad"}, {Option: "unknown=bad"},
{Option: "uri=/|unknown=bad"}, {Option: "uri=/|unknown=bad"},
{Option: "uri"}, {Option: "uri"},
{Option: "uri=hello"},
{Option: "uri=/|white-listed=ERROR"}, {Option: "uri=/|white-listed=ERROR"},
} }
for i, c := range cs { for i, c := range cs {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment