From 377141510005e1b6d67044f557f7367cccc7e659 Mon Sep 17 00:00:00 2001 From: Mike Samuel Date: Mon, 26 Sep 2011 00:56:49 -0700 Subject: [PATCH] exp/template/html: fix infinite loop in escapeText on bad input The template "`, `exp/template/html:z: "'" in unquoted attr: "font:'Arial'"`, }, + { + ``, + `: expected space, attr name, or end of tag, but got "=foo>"`, + }, } for _, test := range tests { diff --git a/src/pkg/exp/template/html/transition.go b/src/pkg/exp/template/html/transition.go index 15548043b6..b8e02b239c 100644 --- a/src/pkg/exp/template/html/transition.go +++ b/src/pkg/exp/template/html/transition.go @@ -100,26 +100,30 @@ func tTag(c context, s []byte) (context, int) { return context{state: stateError, err: err}, len(s) } state, attr := stateTag, attrNone - if i != j { - canonAttrName := strings.ToLower(string(s[i:j])) - switch attrType[canonAttrName] { - case contentTypeURL: - attr = attrURL - case contentTypeCSS: - attr = attrStyle - case contentTypeJS: + if i == j { + return context{ + state: stateError, + err: errorf(ErrBadHTML, 0, "expected space, attr name, or end of tag, but got %q", s[i:]), + }, len(s) + } + canonAttrName := strings.ToLower(string(s[i:j])) + switch attrType[canonAttrName] { + case contentTypeURL: + attr = attrURL + case contentTypeCSS: + attr = attrStyle + case contentTypeJS: + attr = attrScript + default: + if strings.HasPrefix(canonAttrName, "on") { attr = attrScript - default: - if strings.HasPrefix(canonAttrName, "on") { - attr = attrScript - } - } - if j == len(s) { - state = stateAttrName - } else { - state = stateAfterName } } + if j == len(s) { + state = stateAttrName + } else { + state = stateAfterName + } return context{state: state, element: c.element, attr: attr}, j }