diff options
author | Robert Griesemer <gri@golang.org> | 2010-11-17 11:03:33 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2010-11-17 11:03:33 -0800 |
commit | e38b7f49531e8b6aa05fa6a15c7e8527cb668ea6 (patch) | |
tree | 8c353736614b542b70a15c2af873ea97a57483d4 | |
parent | 18ae633472f312026cff8b31c899102e509ab96d (diff) | |
download | go-e38b7f49531e8b6aa05fa6a15c7e8527cb668ea6.tar.gz go-e38b7f49531e8b6aa05fa6a15c7e8527cb668ea6.zip |
godoc: bug fix in relativePath
This fixes a problem with relativePath, where
a prefix was not recognized because it ended
in "//" as opposed to just "/".
Also: Minor unrelated cleanup of a declaration.
R=rsc
CC=golang-dev
https://golang.org/cl/3146041
-rw-r--r-- | src/cmd/godoc/godoc.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 930956c98a..57345e0ea9 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -51,6 +51,7 @@ var ( verbose = flag.Bool("v", false, "verbose mode") // file system roots + // TODO(gri) consider the invariant that goroot always end in '/' goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory") path = flag.String("path", "", "additional package directories (colon-separated)") filter = flag.String("filter", "", "filter file containing permitted package directory paths") @@ -260,9 +261,16 @@ func absolutePath(path, defaultRoot string) string { func relativePath(path string) string { relpath := fsMap.ToRelative(path) - if relpath == "" && strings.HasPrefix(path, *goroot+"/") { - // no user-defined mapping found; use default mapping - relpath = path[len(*goroot)+1:] + if relpath == "" { + // prefix must end in '/' + prefix := *goroot + if len(prefix) > 0 && prefix[len(prefix)-1] != '/' { + prefix += "/" + } + if strings.HasPrefix(path, prefix) { + // no user-defined mapping found; use default mapping + relpath = path[len(prefix):] + } } // Only if path is an invalid absolute path is relpath == "" // at this point. This should never happen since absolute paths @@ -793,7 +801,7 @@ func readTemplates() { // Generic HTML wrapper func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) { - type Data struct { + d := struct { Title string Subtitle string PkgRoots []string @@ -801,16 +809,14 @@ func servePage(w http.ResponseWriter, title, subtitle, query string, content []b Version string Menu []byte Content []byte - } - - d := Data{ - Title: title, - Subtitle: subtitle, - PkgRoots: fsMap.PrefixList(), - Query: query, - Version: runtime.Version(), - Menu: nil, - Content: content, + }{ + title, + subtitle, + fsMap.PrefixList(), + query, + runtime.Version(), + nil, + content, } if err := godocHTML.Execute(&d, w); err != nil { |