aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/html
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2012-04-12 09:35:43 +1000
committerNigel Tao <nigeltao@golang.org>2012-04-12 09:35:43 +1000
commit6277656d69640da9166bbac2a132a3ddee61dcac (patch)
tree6f4080c783f61ea8edd829c8afb329d9ee408628 /src/pkg/html
parent772e8ff4584ac6b97d8f3c38f0b21161ca72fe81 (diff)
downloadgo-6277656d69640da9166bbac2a132a3ddee61dcac.tar.xz
html, exp/html: escape ' and " as &#39; and &#34;, since IE8 and
below do not support &apos;. 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
Diffstat (limited to 'src/pkg/html')
-rw-r--r--src/pkg/html/escape.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/pkg/html/escape.go b/src/pkg/html/escape.go
index fee771a578..24cb7af852 100644
--- a/src/pkg/html/escape.go
+++ b/src/pkg/html/escape.go
@@ -210,13 +210,15 @@ func escape(w writer, s string) error {
case '&':
esc = "&amp;"
case '\'':
- esc = "&apos;"
+ // "&#39;" is shorter than "&apos;" and apos was not in HTML until HTML5.
+ esc = "&#39;"
case '<':
esc = "&lt;"
case '>':
esc = "&gt;"
case '"':
- esc = "&quot;"
+ // "&#34;" is shorter than "&quot;".
+ esc = "&#34;"
default:
panic("unrecognized escape character")
}
@@ -231,7 +233,7 @@ func escape(w writer, s string) error {
}
// EscapeString escapes special characters like "<" to become "&lt;". 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 {