File tree 2 files changed +7
-2
lines changed
2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,12 @@ type Router struct {
46
46
47
47
// URL will prefix the path with the server's host
48
48
func (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
50
55
}
51
56
52
57
// 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) {
88
88
ut .Eq (ut .Req ("" , s .URL ()).String (), "" )
89
89
ut .Has (ut .Req ("" , s .URL ("/file" )).String (), "ysmood/got" )
90
90
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" )
92
92
93
93
ut .Has (ut .Req ("" , s .URL ("/c" )).String (), "ysmood/got" )
94
94
ut .Req (http .MethodPost , s .URL ("/d" ), 1 )
You can’t perform that action at this time.
0 commit comments