mirror of
https://github.com/golang/go
synced 2024-11-18 12:44:49 -07:00
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
This commit is contained in:
parent
0cf8ab65b2
commit
61bd98e5b3
@ -280,6 +280,7 @@ func newPosLink_urlFunc(srcPosLinkFunc func(s string, line, low, high int) strin
|
||||
}
|
||||
|
||||
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 srcPosLinkFunc(s string, line, low, high int) string {
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -35,6 +35,8 @@ func TestSrcPosLinkFunc(t *testing.T) {
|
||||
{"/src/pkg/fmt/print.go", 2, 0, 0, "/src/pkg/fmt/print.go#L2"},
|
||||
{"/src/pkg/fmt/print.go", 0, 0, 0, "/src/pkg/fmt/print.go"},
|
||||
{"/src/pkg/fmt/print.go", 0, 1, 5, "/src/pkg/fmt/print.go?s=1:5#L1"},
|
||||
{"fmt/print.go", 0, 0, 0, "/src/pkg/fmt/print.go"},
|
||||
{"fmt/print.go", 0, 1, 5, "/src/pkg/fmt/print.go?s=1:5#L1"},
|
||||
} {
|
||||
if got, want := srcPosLinkFunc(tc.src, tc.line, tc.low, tc.high), tc.want; got != want {
|
||||
t.Errorf("srcLinkFunc(%v, %v, %v, %v) = %v; want %v", tc.src, tc.line, tc.low, tc.high, got, want)
|
||||
@ -49,6 +51,8 @@ func TestSrcLinkFunc(t *testing.T) {
|
||||
}{
|
||||
{"/src/pkg/fmt/print.go", "/src/pkg/fmt/print.go"},
|
||||
{"src/pkg/fmt/print.go", "/src/pkg/fmt/print.go"},
|
||||
{"/fmt/print.go", "/src/pkg/fmt/print.go"},
|
||||
{"fmt/print.go", "/src/pkg/fmt/print.go"},
|
||||
} {
|
||||
if got, want := srcLinkFunc(tc.src), tc.want; got != want {
|
||||
t.Errorf("srcLinkFunc(%v) = %v; want %v", tc.src, got, want)
|
||||
|
@ -179,7 +179,9 @@
|
||||
{{end}}
|
||||
|
||||
{{with .PAst}}
|
||||
<pre>{{node_html $ . false}}</pre>
|
||||
{{range $filename, $ast := .}}
|
||||
<a href="{{$filename|srcLink|html}}">{{$filename|filename|html}}</a>:<pre>{{node_html $ $ast false}}</pre>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{with .Dirs}}
|
||||
|
@ -705,7 +705,9 @@ $(document).ready(function() {
|
||||
{{end}}
|
||||
|
||||
{{with .PAst}}
|
||||
<pre>{{node_html $ . false}}</pre>
|
||||
{{range $filename, $ast := .}}
|
||||
<a href="{{$filename|srcLink|html}}">{{$filename|filename|html}}</a>:<pre>{{node_html $ $ast false}}</pre>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{with .Dirs}}
|
||||
|
Loading…
Reference in New Issue
Block a user