Skip to content

Commit 3d80b4e

Browse files
authored
fix(internal/godocfx): prevent index out of bounds when pkg == mod (#3768)
1 parent 77f76ed commit 3d80b4e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/godocfx/parse.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ func (l *linker) toURL(pkg, name string) string {
461461
return fmt.Sprintf("#%s", name)
462462
}
463463
if mod, ok := l.sameDomainModules[pkg]; ok {
464-
pkgRemainder := pkg[len(mod.Path)+1:] // +1 to skip slash.
464+
pkgRemainder := ""
465+
if pkg != mod.Path {
466+
pkgRemainder = pkg[len(mod.Path)+1:] // +1 to skip slash.
467+
}
465468
// Note: we always link to latest. One day, we'll link to mod.Version.
466469
baseURL := fmt.Sprintf("/go/docs/reference/%v/latest/%v", mod.Path, pkgRemainder)
467470
if anchor := l.idToAnchor[pkg][name]; anchor != "" {

0 commit comments

Comments
 (0)