1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:06:09 -07:00

godoc/redirect: allow trailing slashes for prefix handlers

This allows URLs like golang.org/wiki/DevExp/, where before only
golang.org/wiki/DevExp was accepted.

Fixes golang/go#19432.

Change-Id: Ie41a4fe1d1930fd947c1d0523060d08c7c6d6d39
Reviewed-on: https://go-review.googlesource.com/37882
Reviewed-by: Jaana Burcu Dogan <jbd@google.com>
This commit is contained in:
Chris Broadfoot 2017-03-06 20:52:45 -08:00
parent d332283808
commit b282a57667
2 changed files with 4 additions and 1 deletions

View File

@ -150,7 +150,7 @@ func Handler(target string) http.Handler {
})
}
var validId = regexp.MustCompile(`^[A-Za-z0-9-]*$`)
var validId = regexp.MustCompile(`^[A-Za-z0-9-]*/?$`)
func PrefixHandler(prefix, baseURL string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

View File

@ -50,6 +50,9 @@ func TestRedirects(t *testing.T) {
"/issues/new": {301, "https://github.com/golang/go/issues/new"},
"/issues/1/2/3": errorResult(404),
"/wiki/foo": {302, "https://github.com/golang/go/wiki/foo"},
"/wiki/foo/": {302, "https://github.com/golang/go/wiki/foo/"},
"/design": {301, "https://github.com/golang/proposal/tree/master/design"},
"/design/": {302, "/design"},
"/design/123-foo": {302, "https://github.com/golang/proposal/blob/master/design/123-foo.md"},