From: Mike Samuel Date: Mon, 26 Sep 2011 07:42:38 +0000 (-0700) Subject: exp/template/html: error out on ambiguous unquoted attributes X-Git-Tag: weekly.2011-10-06~102 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=66cdd020382760e502fe456f753156f6fa6a2867;p=gostls13.git exp/template/html: error out on ambiguous unquoted attributes HTML parsers may differ on whether U+0022 QUOTATION MARK (") \> U+0027 APOSTROPHE (') \> U+003C LESS-THAN SIGN (<) \> U+003D EQUALS SIGN (=) \> U+0060 GRAVE ACCENT (`) Parse error. Treat it as per the "anything else" entry below. and emits ErrBadHTML. R=nigeltao CC=golang-dev https://golang.org/cl/5085050 --- diff --git a/src/pkg/exp/template/html/escape.go b/src/pkg/exp/template/html/escape.go index 650a6acd28..aa5427c098 100644 --- a/src/pkg/exp/template/html/escape.go +++ b/src/pkg/exp/template/html/escape.go @@ -626,6 +626,24 @@ func contextAfterText(c context, s []byte) (context, int) { i := bytes.IndexAny(s, delimEnds[c.delim]) if i == -1 { + i = len(s) + } + if c.delim == delimSpaceOrTagEnd { + // http://www.w3.org/TR/html5/tokenization.html#attribute-value-unquoted-state + // lists the runes below as error characters. + // Error out because HTML parsers may differ on whether + // "= 0 { + return context{ + state: stateError, + err: errorf(ErrBadHTML, 0, "%q in unquoted attr: %q", s[j:j+1], s[:i]), + }, len(s) + } + } + if i == len(s) { // Remain inside the attribute. // Decode the value so non-HTML rules can easily handle //