From 7f57f6be9bd1bfd2e207b163d6298ecd87803dee Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Wed, 3 Mar 2021 11:23:18 -0500 Subject: [PATCH] fix(internal/godocfx): prevent index out of bounds when pkg == mod --- internal/godocfx/parse.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/godocfx/parse.go b/internal/godocfx/parse.go index 68ce87ef924..cabe8ceb834 100644 --- a/internal/godocfx/parse.go +++ b/internal/godocfx/parse.go @@ -461,7 +461,10 @@ func (l *linker) toURL(pkg, name string) string { return fmt.Sprintf("#%s", name) } if mod, ok := l.sameDomainModules[pkg]; ok { - pkgRemainder := pkg[len(mod.Path)+1:] // +1 to skip slash. + pkgRemainder := "" + if pkg != mod.Path { + pkgRemainder = pkg[len(mod.Path)+1:] // +1 to skip slash. + } // Note: we always link to latest. One day, we'll link to mod.Version. baseURL := fmt.Sprintf("/go/docs/reference/%v/latest/%v", mod.Path, pkgRemainder) if anchor := l.idToAnchor[pkg][name]; anchor != "" {