From 293ebe14936bf5aa585139c72ea2f28d4164f984 Mon Sep 17 00:00:00 2001 From: ShaneSaww Date: Sun, 15 Jan 2017 21:47:00 -0800 Subject: [PATCH] Adding in a check for routes with just / --- mux_test.go | 10 ++++++++++ route.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mux_test.go b/mux_test.go index 39a099c..bbde290 100644 --- a/mux_test.go +++ b/mux_test.go @@ -1017,6 +1017,7 @@ func TestBuildVarsFunc(t *testing.T) { func TestSubRouter(t *testing.T) { subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter() subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter() + subrouter3 := new(Route).PathPrefix("/foo").Subrouter() tests := []routeTest{ { @@ -1048,6 +1049,15 @@ func TestSubRouter(t *testing.T) { pathTemplate: `/foo/{v1}/baz/{v2}`, shouldMatch: true, }, + { + route: subrouter3.Path("/"), + request: newRequest("GET", "http://localhost/foo/"), + vars: map[string]string{}, + host: "", + path: "/foo/", + pathTemplate: `/foo/`, + shouldMatch: true, + }, { route: subrouter2.Path("/baz/{v2}"), request: newRequest("GET", "http://localhost/foo/bar"), diff --git a/route.go b/route.go index 293b6d4..9221915 100644 --- a/route.go +++ b/route.go @@ -153,7 +153,7 @@ func (r *Route) addRegexpMatcher(tpl string, matchHost, matchPrefix, matchQuery } r.regexp = r.getRegexpGroup() if !matchHost && !matchQuery { - if len(tpl) == 0 || tpl[0] != '/' { + if tpl == "/" && (len(tpl) == 0 || tpl[0] != '/') { return fmt.Errorf("mux: path must start with a slash, got %q", tpl) } if r.regexp.path != nil {