]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: canonicalize custom path redirects
authorAndrew Gerrand <adg@golang.org>
Tue, 27 Mar 2012 01:44:17 +0000 (12:44 +1100)
committerAndrew Gerrand <adg@golang.org>
Tue, 27 Mar 2012 01:44:17 +0000 (12:44 +1100)
For example, /ref and /doc/reference.html now both redirect to /ref/.

Fixes #3401.

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

src/cmd/godoc/godoc.go

index 26814d2fa3d96246c2b921d699f5765695c4f08b..f21c20496ce30daad08cd3e069448effc36992da 100644 (file)
@@ -1315,7 +1315,18 @@ func refreshMetadataLoop() {
 //
 func metadataFor(relpath string) *Metadata {
        if m, _ := docMetadata.get(); m != nil {
-               return m.(map[string]*Metadata)[relpath]
+               meta := m.(map[string]*Metadata)
+               // If metadata for this relpath exists, return it.
+               if p := meta[relpath]; p != nil {
+                       return p
+               }
+               // Try with or without trailing slash.
+               if strings.HasSuffix(relpath, "/") {
+                       relpath = relpath[:len(relpath)-1]
+               } else {
+                       relpath = relpath + "/"
+               }
+               return meta[relpath]
        }
        return nil
 }