From c05c3a9d1180e6d449049d9ed96c46b65837bb29 Mon Sep 17 00:00:00 2001 From: Scott Lawrence Date: Fri, 24 Feb 2012 11:32:33 +1100 Subject: [PATCH] html/template: make doctype check case-insensitive Fixes #3094. R=golang-dev, rsc, nigeltao CC=golang-dev https://golang.org/cl/5687065 --- src/pkg/html/template/escape.go | 2 +- src/pkg/html/template/escape_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pkg/html/template/escape.go b/src/pkg/html/template/escape.go index 02fa3eaad6b..a058e20d7b3 100644 --- a/src/pkg/html/template/escape.go +++ b/src/pkg/html/template/escape.go @@ -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("<") written = j + 1 diff --git a/src/pkg/html/template/escape_test.go b/src/pkg/html/template/escape_test.go index 70cada3f50b..a92a0596c76 100644 --- a/src/pkg/html/template/escape_test.go +++ b/src/pkg/html/template/escape_test.go @@ -431,6 +431,11 @@ func TestEscape(t *testing.T) { "Hello, World!", "Hello, World!", }, + { + "HTML doctype not case-insensitive", + "Hello, World!", + "Hello, World!", + }, { "No doctype injection", `