1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:14:40 -07:00

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 { func (m *Mapping) ToRelative(fpath string) string {
for _, e := range m.list { 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) spath := filepath.ToSlash(fpath)
// /absolute/prefix/foo -> prefix/foo // /absolute/prefix/foo -> prefix/foo
return path.Join(e.prefix, spath[len(e.path):]) // Join will remove a trailing '/' return path.Join(e.prefix, spath[len(e.path):]) // Join will remove a trailing '/'