Skip to content

Commit 7d0ea0a

Browse files
wdhongtwfindleyr
authored andcommitted
internal/godoc/dochtml: enhance output parsing for example func
Current logic for detecting "concluding line comment" is not strict enough that it may cause false-positive, causing some normal comment (and code following it) to be discarded in the rendered web page. Ensure that "concluding line comment" can only be prefixed by spaces. Also add corresponding test case. Fixes golang/go#65450 Change-Id: Ief9ec5326aa94965ca02d3278398cc5663ba395f GitHub-Last-Rev: 7312ff3 GitHub-Pull-Request: #93 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/600415 kokoro-CI: kokoro <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 47024e5 commit 7d0ea0a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

internal/godoc/dochtml/internal/render/linkify_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ b := 1
296296
line comment.
297297
*/
298298
</pre>
299+
`,
300+
},
301+
{
302+
"An Output comment must appear at the start of the line.",
303+
`_ = true
304+
// This comment containing "// Output:" is not treated specially.
305+
`,
306+
`
307+
<pre class="Documentation-exampleCode">
308+
_ = true
309+
// This comment containing &#34;// Output:&#34; is not treated specially.
310+
</pre>
299311
`,
300312
},
301313
} {

internal/godoc/dochtml/internal/render/render.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121

2222
var (
2323
// Regexp for example outputs.
24-
exampleOutputRx = regexp.MustCompile(`(?i)//[[:space:]]*(unordered )?output:`)
24+
// Keep consistent with outputPrefix in GOROOT/src/go/doc/example.go.
25+
exampleOutputRx = regexp.MustCompile(`(?i)^[[:space:]]*//[[:space:]]*(unordered )?output:`)
2526
)
2627

2728
type Renderer struct {

0 commit comments

Comments
 (0)