]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: fix redirect loop for URL "/".
authorSameer Ajmani <sameer@golang.org>
Wed, 1 Feb 2012 14:43:22 +0000 (09:43 -0500)
committerSameer Ajmani <sameer@golang.org>
Wed, 1 Feb 2012 14:43:22 +0000 (09:43 -0500)
R=golang-dev, bradfitz, rsc, adg
CC=golang-dev
https://golang.org/cl/5606045

src/cmd/godoc/godoc.go

index e3ac3d2bd10b5f1c9d42a1694e4411f3f4dd1e88..a4a0d8333c4a74c3b3ecea3fed8de497abfdd6cb 100644 (file)
@@ -499,7 +499,7 @@ func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.File
        for _, eg := range examples {
                name := eg.Name
 
-               // strip lowercase braz in Foo_braz or Foo_Bar_braz from name 
+               // strip lowercase braz in Foo_braz or Foo_Bar_braz from name
                // while keeping uppercase Braz in Foo_Braz
                if i := strings.LastIndex(name, "_"); i != -1 {
                        if i < len(name)-1 && !startsWithUppercase(name[i+1:]) {
@@ -743,7 +743,11 @@ func applyTemplate(t *template.Template, name string, data interface{}) []byte {
 }
 
 func redirect(w http.ResponseWriter, r *http.Request) (redirected bool) {
-       if canonical := path.Clean(r.URL.Path) + "/"; r.URL.Path != canonical {
+       canonical := path.Clean(r.URL.Path)
+       if !strings.HasSuffix("/", canonical) {
+               canonical += "/"
+       }
+       if r.URL.Path != canonical {
                http.Redirect(w, r, canonical, http.StatusMovedPermanently)
                redirected = true
        }