Skip to content

Commit d8ea390

Browse files
davidbenCQ bot account: commit-bot@chromium.org
authored and
CQ bot account: [email protected]
committed
Fix doc.go against Go tip.
Go 1.9 is slated to have some backwards-incompatible changes to html/template. See golang/go#19952. If I'm reading this correctly, the issue is that the context-aware auto escaper had some magic around the 'html' filter, but it would get confused if this was used in the wrong context. This does not apply to us because we never used it in an attribute, etc. Nonetheless, we can be compatible with it and tidy up markupPipeWords' type signature. It should have had type template.HTML -> template.HTML, not string -> template.HTML, because it expects the input to be pre-escaped. (The old 'html' escaper, in turn, probably should have had type string -> template.HTML, but I guess it didn't because all this existed for a text/template migration convenience of some sort?) I considered adding our own escapeHTML with type string -> template.HTML and fixing markupPipeWords to be template.HTML -> template.HTML, but markupPipeWords does not correctly handle all possible template.HTML input. If a | were in an attribute somewhere, it would mangle the text. Instead, I kept it of type string -> template.HTML and defined it to perform the HTML escaping itself. This seems to produce the same output as before in Go 1.8 and tip. Change-Id: I90618a3c5525ae54f9fe731352fcff5856b9ba60 Reviewed-on: https://boringssl-review.googlesource.com/18944 Commit-Queue: Adam Langley <[email protected]> Reviewed-by: Adam Langley <[email protected]> CQ-Verified: CQ bot account: [email protected] <[email protected]>
1 parent 26ababb commit d8ea390

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

util/doc.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,13 @@ func firstSentence(paragraphs []string) string {
459459
return s
460460
}
461461

462+
// markupPipeWords converts |s| into an HTML string, safe to be included outside
463+
// a tag, while also marking up words surrounded by |.
462464
func markupPipeWords(allDecls map[string]string, s string) template.HTML {
465+
// It is safe to look for '|' in the HTML-escaped version of |s|
466+
// below. The escaped version cannot include '|' instead tags because
467+
// there are no tags by construction.
468+
s = template.HTMLEscapeString(s)
463469
ret := ""
464470

465471
for {
@@ -549,12 +555,12 @@ func generate(outPath string, config *Config) (map[string]string, error) {
549555
<a href="headers.html">All headers</a>
550556
</div>
551557
552-
{{range .Preamble}}<p>{{. | html | markupPipeWords}}</p>{{end}}
558+
{{range .Preamble}}<p>{{. | markupPipeWords}}</p>{{end}}
553559
554560
<ol>
555561
{{range .Sections}}
556562
{{if not .IsPrivate}}
557-
{{if .Anchor}}<li class="header"><a href="#{{.Anchor}}">{{.Preamble | firstSentence | html | markupPipeWords}}</a></li>{{end}}
563+
{{if .Anchor}}<li class="header"><a href="#{{.Anchor}}">{{.Preamble | firstSentence | markupPipeWords}}</a></li>{{end}}
558564
{{range .Decls}}
559565
{{if .Anchor}}<li><a href="#{{.Anchor}}"><tt>{{.Name}}</tt></a></li>{{end}}
560566
{{end}}
@@ -567,14 +573,14 @@ func generate(outPath string, config *Config) (map[string]string, error) {
567573
<div class="section" {{if .Anchor}}id="{{.Anchor}}"{{end}}>
568574
{{if .Preamble}}
569575
<div class="sectionpreamble">
570-
{{range .Preamble}}<p>{{. | html | markupPipeWords}}</p>{{end}}
576+
{{range .Preamble}}<p>{{. | markupPipeWords}}</p>{{end}}
571577
</div>
572578
{{end}}
573579
574580
{{range .Decls}}
575581
<div class="decl" {{if .Anchor}}id="{{.Anchor}}"{{end}}>
576582
{{range .Comment}}
577-
<p>{{. | html | markupPipeWords | newlinesToBR | markupFirstWord}}</p>
583+
<p>{{. | markupPipeWords | newlinesToBR | markupFirstWord}}</p>
578584
{{end}}
579585
<pre>{{.Decl}}</pre>
580586
</div>

0 commit comments

Comments
 (0)