]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: make doctype check case-insensitive
authorScott Lawrence <bytbox@gmail.com>
Fri, 24 Feb 2012 00:32:33 +0000 (11:32 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 24 Feb 2012 00:32:33 +0000 (11:32 +1100)
Fixes #3094.

R=golang-dev, rsc, nigeltao
CC=golang-dev
https://golang.org/cl/5687065

src/pkg/html/template/escape.go
src/pkg/html/template/escape_test.go

index 02fa3eaad6bdb3ff447c0670d87ce9056e199d91..a058e20d7b340701658708f2f02e4ee0a32483ad 100644 (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
index 70cada3f50b07a62258bf3d39e04f1ab674d7e92..a92a0596c760ea4025483e398b22114a11d63f96 100644 (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"}}`,