]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: fix buggy use of strings.HasSuffix
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 30 Jan 2013 20:30:26 +0000 (12:30 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 30 Jan 2013 20:30:26 +0000 (12:30 -0800)
This code never worked. Maybe it's not necessary?

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7225070

src/cmd/godoc/godoc.go

index 54cd8ef2d5eb24933ae81a198a059cc82cb7d848..4d66c3011cad7e4a66ef7c3d3a232cff046770c6 100644 (file)
@@ -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