File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,15 @@ func TestPathPrefix(t *testing.T) {
214214 path : "/111" ,
215215 shouldMatch : true ,
216216 },
217+ {
218+ title : "PathPrefix route, match substring" ,
219+ route : new (Route ).PathPrefix ("/1" ),
220+ request : newRequest ("GET" , "http://localhost/111/222/333" ),
221+ vars : map [string ]string {},
222+ host : "" ,
223+ path : "/1" ,
224+ shouldMatch : true ,
225+ },
217226 {
218227 title : "PathPrefix route, URL prefix in request does not match" ,
219228 route : new (Route ).PathPrefix ("/111" ),
Original file line number Diff line number Diff line change @@ -259,7 +259,8 @@ func (r *Route) Methods(methods ...string) *Route {
259259// Path -----------------------------------------------------------------------
260260
261261// Path adds a matcher for the URL path.
262- // It accepts a template with zero or more URL variables enclosed by {}.
262+ // It accepts a template with zero or more URL variables enclosed by {}. The
263+ // template must start with a "/".
263264// Variables can define an optional regexp pattern to me matched:
264265//
265266// - {name} matches anything until the next slash.
@@ -283,7 +284,10 @@ func (r *Route) Path(tpl string) *Route {
283284
284285// PathPrefix -----------------------------------------------------------------
285286
286- // PathPrefix adds a matcher for the URL path prefix.
287+ // PathPrefix adds a matcher for the URL path prefix. Note that it does not
288+ // treat slashes specially ("/foobar/" will be matched by the prefix "/foo") so
289+ // in most cases you'll want to use a trailing slash here. See Route.Path() for
290+ // details on the tpl argument.
287291func (r * Route ) PathPrefix (tpl string ) * Route {
288292 r .strictSlash = false
289293 r .err = r .addRegexpMatcher (tpl , false , true )
You can’t perform that action at this time.
0 commit comments