Skip to content

Commit

Permalink
Rule parsing error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and traefiker committed Oct 4, 2018
1 parent 31f9200 commit ec86149
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions rules/rules.go
Expand Up @@ -269,6 +269,9 @@ func (r *Rules) Parse(expression string) (*mux.Route, error) {
if r.err != nil {
return r.err
}
if resultRoute == nil {
return fmt.Errorf("invalid expression: %s", expression)
}
if resultRoute.GetError() != nil {
return resultRoute.GetError()
}
Expand Down
20 changes: 16 additions & 4 deletions rules/rules_test.go
Expand Up @@ -218,11 +218,17 @@ func TestHostRegexp(t *testing.T) {
}
}

type fakeHandler struct {
name string
}
func TestParseInvalidSyntax(t *testing.T) {
router := mux.NewRouter()
router.StrictSlash(true)

func (h *fakeHandler) ServeHTTP(http.ResponseWriter, *http.Request) {}
rules := &Rules{Route: &types.ServerRoute{Route: router.NewRoute()}}
expression01 := "Path: /path1;Query:param_one=true, /path2"

routeFoo, err := rules.Parse(expression01)
require.Error(t, err)
assert.Nil(t, routeFoo)
}

func TestPathPrefix(t *testing.T) {
testCases := []struct {
Expand Down Expand Up @@ -287,3 +293,9 @@ func TestPathPrefix(t *testing.T) {
})
}
}

type fakeHandler struct {
name string
}

func (h *fakeHandler) ServeHTTP(http.ResponseWriter, *http.Request) {}

0 comments on commit ec86149

Please sign in to comment.