diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 54cd8ef2d5..4d66c3011c 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -652,7 +652,7 @@ func applyTemplate(t *template.Template, name string, data interface{}) []byte { func redirect(w http.ResponseWriter, r *http.Request) (redirected bool) { canonical := pathpkg.Clean(r.URL.Path) - if !strings.HasSuffix("/", canonical) { + if !strings.HasSuffix(canonical, "/") { canonical += "/" } if r.URL.Path != canonical { @@ -666,9 +666,7 @@ func redirect(w http.ResponseWriter, r *http.Request) (redirected bool) { func redirectFile(w http.ResponseWriter, r *http.Request) (redirected bool) { c := pathpkg.Clean(r.URL.Path) - for strings.HasSuffix("/", c) { - c = c[:len(c)-1] - } + c = strings.TrimRight(c, "/") if r.URL.Path != c { url := *r.URL url.Path = c