godoc: fix absolute->relative mapping

Fixes #3096.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5690063
This commit is contained in:
Robert Griesemer 2012-02-21 18:12:37 -08:00
parent 8542dc0764
commit 7b22e46282

View file

@ -178,7 +178,8 @@ func (m *Mapping) ToAbsolute(spath string) string {
//
func (m *Mapping) ToRelative(fpath string) string {
for _, e := range m.list {
if strings.HasPrefix(fpath, e.path) {
// if fpath has prefix e.path, the next character must be a separator (was issue 3096)
if strings.HasPrefix(fpath, e.path) && fpath[len(e.path)] == filepath.Separator {
spath := filepath.ToSlash(fpath)
// /absolute/prefix/foo -> prefix/foo
return path.Join(e.prefix, spath[len(e.path):]) // Join will remove a trailing '/'