From 15732269da23c35524bf7cabea5857e4c5f63881 Mon Sep 17 00:00:00 2001 From: Steven Bower Date: Thu, 17 Nov 2016 09:36:10 -0500 Subject: [PATCH] Fixes #851 (#852) --- rules.go | 8 ++++---- rules_test.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/rules.go b/rules.go index 96cc73b6e..3bb6edca7 100644 --- a/rules.go +++ b/rules.go @@ -45,7 +45,7 @@ func (r *Rules) hostRegexp(hosts ...string) *mux.Route { func (r *Rules) path(paths ...string) *mux.Route { router := r.route.route.Subrouter() for _, path := range paths { - router.Path(types.CanonicalDomain(path)) + router.Path(strings.TrimSpace(path)) } return r.route.route } @@ -53,7 +53,7 @@ func (r *Rules) path(paths ...string) *mux.Route { func (r *Rules) pathPrefix(paths ...string) *mux.Route { router := r.route.route.Subrouter() for _, path := range paths { - router.PathPrefix(types.CanonicalDomain(path)) + router.PathPrefix(strings.TrimSpace(path)) } return r.route.route } @@ -69,7 +69,7 @@ func (r *Rules) pathStrip(paths ...string) *mux.Route { r.route.stripPrefixes = paths router := r.route.route.Subrouter() for _, path := range paths { - router.Path(types.CanonicalDomain(path)) + router.Path(strings.TrimSpace(path)) } return r.route.route } @@ -79,7 +79,7 @@ func (r *Rules) pathPrefixStrip(paths ...string) *mux.Route { r.route.stripPrefixes = paths router := r.route.route.Subrouter() for _, path := range paths { - router.PathPrefix(types.CanonicalDomain(path)) + router.PathPrefix(strings.TrimSpace(path)) } return r.route.route } diff --git a/rules_test.go b/rules_test.go index 694fde089..72c712423 100644 --- a/rules_test.go +++ b/rules_test.go @@ -40,15 +40,23 @@ func TestParseTwoRules(t *testing.T) { routeResult, err := rules.Parse(expression) if err != nil { - t.Fatal("Error while building route for Host:foo.bar;Path:/foobar") + t.Fatal("Error while building route for Host:foo.bar;Path:/FOObar") } request, err := http.NewRequest("GET", "http://foo.bar/foobar", nil) routeMatch := routeResult.Match(request, &mux.RouteMatch{Route: routeResult}) + if routeMatch == true { + t.Log(err) + t.Fatal("Rule Host:foo.bar;Path:/FOObar don't match") + } + + request, err = http.NewRequest("GET", "http://foo.bar/FOObar", nil) + routeMatch = routeResult.Match(request, &mux.RouteMatch{Route: routeResult}) + if routeMatch == false { t.Log(err) - t.Fatal("Rule Host:foo.bar;Path:/foobar don't match") + t.Fatal("Rule Host:foo.bar;Path:/FOObar don't match") } }