godoc: Fix m=src URLs.
For source code links, prepend /src/pkg if not already prefixed.
Fixes golang/go#7383.
R=bradfitz, sameer
CC=golang-codereviews
https://golang.org/cl/67110043
diff --git a/godoc/godoc.go b/godoc/godoc.go
index 7964b52..b0e721a 100644
--- a/godoc/godoc.go
+++ b/godoc/godoc.go
@@ -280,6 +280,7 @@
}
func srcPosLinkFunc(s string, line, low, high int) string {
+ s = srcLinkFunc(s)
var buf bytes.Buffer
template.HTMLEscape(&buf, []byte(s))
// selection ranges are of form "s=low:high"
@@ -301,7 +302,11 @@
}
func srcLinkFunc(s string) string {
- return pathpkg.Clean("/" + s)
+ s = pathpkg.Clean("/" + s)
+ if !strings.HasPrefix(s, "/src/pkg/") {
+ s = "/src/pkg" + s
+ }
+ return s
}
// queryLinkFunc returns a URL for a line in a source file with a highlighted