Commit e38b7f49 authored by Robert Griesemer's avatar Robert Griesemer

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
parent 18ae6334
...@@ -51,6 +51,7 @@ var ( ...@@ -51,6 +51,7 @@ var (
verbose = flag.Bool("v", false, "verbose mode") verbose = flag.Bool("v", false, "verbose mode")
// file system roots // file system roots
// TODO(gri) consider the invariant that goroot always end in '/'
goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory") goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory")
path = flag.String("path", "", "additional package directories (colon-separated)") path = flag.String("path", "", "additional package directories (colon-separated)")
filter = flag.String("filter", "", "filter file containing permitted package directory paths") filter = flag.String("filter", "", "filter file containing permitted package directory paths")
...@@ -260,9 +261,16 @@ func absolutePath(path, defaultRoot string) string { ...@@ -260,9 +261,16 @@ func absolutePath(path, defaultRoot string) string {
func relativePath(path string) string { func relativePath(path string) string {
relpath := fsMap.ToRelative(path) relpath := fsMap.ToRelative(path)
if relpath == "" && strings.HasPrefix(path, *goroot+"/") { if relpath == "" {
// no user-defined mapping found; use default mapping // prefix must end in '/'
relpath = path[len(*goroot)+1:] 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 == "" // Only if path is an invalid absolute path is relpath == ""
// at this point. This should never happen since absolute paths // at this point. This should never happen since absolute paths
...@@ -793,7 +801,7 @@ func readTemplates() { ...@@ -793,7 +801,7 @@ func readTemplates() {
// Generic HTML wrapper // Generic HTML wrapper
func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) { func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) {
type Data struct { d := struct {
Title string Title string
Subtitle string Subtitle string
PkgRoots []string PkgRoots []string
...@@ -801,16 +809,14 @@ func servePage(w http.ResponseWriter, title, subtitle, query string, content []b ...@@ -801,16 +809,14 @@ func servePage(w http.ResponseWriter, title, subtitle, query string, content []b
Version string Version string
Menu []byte Menu []byte
Content []byte Content []byte
} }{
title,
d := Data{ subtitle,
Title: title, fsMap.PrefixList(),
Subtitle: subtitle, query,
PkgRoots: fsMap.PrefixList(), runtime.Version(),
Query: query, nil,
Version: runtime.Version(), content,
Menu: nil,
Content: content,
} }
if err := godocHTML.Execute(&d, w); err != nil { if err := godocHTML.Execute(&d, w); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment