Skip to content

Commit a5c2535

Browse files
committed
Use html escaper function from html/template
1 parent e3ee57d commit a5c2535

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

mustache.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7+
"html/template"
78
"io"
89
"io/ioutil"
910
"os"
@@ -53,32 +54,6 @@ var (
5354
esc_gt = []byte(">")
5455
)
5556

56-
// taken from pkg/template
57-
func htmlEscape(w io.Writer, s []byte) {
58-
var esc []byte
59-
last := 0
60-
for i, c := range s {
61-
switch c {
62-
case '"':
63-
esc = esc_quot
64-
case '\'':
65-
esc = esc_apos
66-
case '&':
67-
esc = esc_amp
68-
case '<':
69-
esc = esc_lt
70-
case '>':
71-
esc = esc_gt
72-
default:
73-
continue
74-
}
75-
w.Write(s[last:i])
76-
w.Write(esc)
77-
last = i + 1
78-
}
79-
w.Write(s[last:])
80-
}
81-
8257
func (tmpl *Template) readString(s string) (string, error) {
8358
i := tmpl.p
8459
newlines := 0
@@ -390,7 +365,7 @@ Outer:
390365
}
391366
}
392367
if name == "." {
393-
return v
368+
return v
394369
}
395370
switch av := v; av.Kind() {
396371
case reflect.Ptr:
@@ -509,7 +484,7 @@ func renderElement(element interface{}, contextChain []interface{}, buf io.Write
509484
fmt.Fprint(buf, val.Interface())
510485
} else {
511486
s := fmt.Sprint(val.Interface())
512-
htmlEscape(buf, []byte(s))
487+
template.HTMLEscape(buf, []byte(s))
513488
}
514489
}
515490
case *sectionElement:

0 commit comments

Comments
 (0)