]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: fix absolute->relative mapping
authorRobert Griesemer <gri@golang.org>
Wed, 22 Feb 2012 02:12:37 +0000 (18:12 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 22 Feb 2012 02:12:37 +0000 (18:12 -0800)
Fixes #3096.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5690063

src/cmd/godoc/mapping.go

index 89e531e2f3d1ffbd45de3ba433dc61c2f1697579..1a0da15bfcd7b8c91acca2f7c77e631124597c0b 100644 (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 '/'