««« backport
a70135896879
html, exp/html: escape ' and " as ' and ", since IE8 and
below do not support '.
This makes package html consistent with package text/template's
HTMLEscape function.
Fixes #3489.
R=rsc, mikesamuel, dsymonds
CC=golang-dev
https://golang.org/cl/
5992071
»»»
case '&':
esc = "&"
case '\'':
- esc = "'"
+ // "'" is shorter than "'" and apos was not in HTML until HTML5.
+ esc = "'"
case '<':
esc = "<"
case '>':
esc = ">"
case '"':
- esc = """
+ // """ is shorter than """.
+ esc = """
default:
panic("unrecognized escape character")
}
}
// EscapeString escapes special characters like "<" to become "<". It
-// escapes only five such characters: amp, apos, lt, gt and quot.
+// escapes only five such characters: <, >, &, ' and ".
// UnescapeString(EscapeString(s)) == s always holds, but the converse isn't
// always true.
func EscapeString(s string) string {
"&", "&",
"<", "<",
">", ">",
- `"`, """,
- "'", "'",
+ // """ is shorter than """.
+ `"`, """,
+ // "'" is shorter than "'" and apos was not in HTML until HTML5.
+ "'", "'",
)
func htmlEscape(s string) string {
var (
htmlQuot = []byte(""") // shorter than """
- htmlApos = []byte("'") // shorter than "'"
+ htmlApos = []byte("'") // shorter than "'" and apos was not in HTML until HTML5
htmlAmp = []byte("&")
htmlLt = []byte("<")
htmlGt = []byte(">")