From 8a452c0fa660a89d1d2ab39c7bf69b59ddb087a2 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 10 Dec 2017 12:08:22 +1300 Subject: [PATCH] standardise html-escaping functions --- ArchiveState.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ArchiveState.go b/ArchiveState.go index 0519514..be62065 100644 --- a/ArchiveState.go +++ b/ArchiveState.go @@ -4,7 +4,6 @@ import ( "bufio" "fmt" "html" - "html/template" "io/ioutil" "math" "net/http" @@ -74,7 +73,7 @@ func (this *ArchiveState) renderView(w http.ResponseWriter) { output := "" for i := startLine; i < endLine; i += 1 { - output += template.HTMLEscapeString(lines[i]) + "
\n" + output += html.EscapeString(lines[i]) + "
\n" } this.renderTemplate(w, []byte(output)) @@ -132,7 +131,7 @@ func (this *ArchiveState) renderSearch(w http.ResponseWriter) { lineNo := i % this.svr.cfg.LinesPerPage url := fmt.Sprintf(`/%s/%d/%d/page-%d#line-%d`, this.logBestSlug, ympair.Year, ympair.Month, page, lineNo) - w.Write([]byte(`
  • » ` + template.HTMLEscapeString(scanner.Text()) + `
  • `)) + w.Write([]byte(`
  • » ` + html.EscapeString(scanner.Text()) + `
  • `)) } }() @@ -141,7 +140,7 @@ func (this *ArchiveState) renderSearch(w http.ResponseWriter) { w.Write([]byte(``)) if totalResults == 0 { - w.Write([]byte(`No search results for "` + template.HTMLEscapeString(this.query) + `"`)) + w.Write([]byte(`No search results for "` + html.EscapeString(this.query) + `"`)) } else { w.Write([]byte(`
    Found ` + fmt.Sprintf("%d", totalResults) + ` total result(s).

    `)) } @@ -151,7 +150,7 @@ func (this *ArchiveState) renderSearch(w http.ResponseWriter) { // renderError renders a plain text string, escaping it for HTML use. func (this *ArchiveState) renderError(w http.ResponseWriter, msg string) { - this.renderTemplate(w, []byte(template.HTMLEscapeString(msg))) + this.renderTemplate(w, []byte(html.EscapeString(msg))) } func (this *ArchiveState) renderTemplate(w http.ResponseWriter, body []byte) { @@ -177,7 +176,7 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) { - ` + template.HTMLEscapeString(title) + ` + ` + html.EscapeString(title) + ` @@ -206,7 +205,7 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) { slug, _ := this.svr.bestSlugFor(&this.svr.cfg.Logs[i]) current := (this.log == &this.svr.cfg.Logs[i]) - w.Write([]byte(``)) + w.Write([]byte(``)) } w.Write([]byte(` @@ -218,7 +217,7 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) { w.Write([]byte(`
    - + - + +