1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:14:42 -07:00

html/template: make doctype check case-insensitive

Fixes #3094.

R=golang-dev, rsc, nigeltao
CC=golang-dev
https://golang.org/cl/5687065
This commit is contained in:
Scott Lawrence 2012-02-24 11:32:33 +11:00 committed by Nigel Tao
parent 19bab1dc78
commit c05c3a9d11
2 changed files with 6 additions and 1 deletions

View File

@ -593,7 +593,7 @@ func (e *escaper) escapeText(c context, n *parse.TextNode) context {
}
}
for j := i; j < end; j++ {
if s[j] == '<' && !bytes.HasPrefix(s[j:], doctypeBytes) {
if s[j] == '<' && !bytes.HasPrefix(bytes.ToUpper(s[j:]), doctypeBytes) {
b.Write(s[written:j])
b.WriteString("&lt;")
written = j + 1

View File

@ -431,6 +431,11 @@ func TestEscape(t *testing.T) {
"<!DOCTYPE html>Hello, World!",
"<!DOCTYPE html>Hello, World!",
},
{
"HTML doctype not case-insensitive",
"<!doCtYPE htMl>Hello, World!",
"<!doCtYPE htMl>Hello, World!",
},
{
"No doctype injection",
`<!{{"DOCTYPE"}}`,