File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,12 @@ type Router struct {
4646
4747// URL will prefix the path with the server's host
4848func (rt * Router ) URL (path ... string ) string {
49- return rt .HostURL .String () + strings .Join (path , "" )
49+ p := strings .Join (path , "" )
50+ if ! strings .HasPrefix (p , "/" ) {
51+ p = "/" + p
52+ }
53+
54+ return rt .HostURL .String () + p
5055}
5156
5257// Route on the pattern. Check the doc of [http.ServeMux] for the syntax of pattern.
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ func TestHelper(t *testing.T) {
8888 ut .Eq (ut .Req ("" , s .URL ()).String (), "" )
8989 ut .Has (ut .Req ("" , s .URL ("/file" )).String (), "ysmood/got" )
9090 ut .Eq (ut .Req ("" , s .URL ("/a" )).String (), "ok" )
91- ut .Eq (ut .Req ("" , s .URL ("/ a" )).String (), "ok" )
91+ ut .Eq (ut .Req ("" , s .URL ("a" )).String (), "ok" )
9292
9393 ut .Has (ut .Req ("" , s .URL ("/c" )).String (), "ysmood/got" )
9494 ut .Req (http .MethodPost , s .URL ("/d" ), 1 )
You can’t perform that action at this time.
0 commit comments