diff --git a/src/pkg/exp/template/html/context.go b/src/pkg/exp/template/html/context.go index 57d44938ca..de073f134a 100644 --- a/src/pkg/exp/template/html/context.go +++ b/src/pkg/exp/template/html/context.go @@ -175,6 +175,15 @@ func isComment(s state) bool { return false } +// isInTag return whether s occurs solely inside an HTML tag. +func isInTag(s state) bool { + switch s { + case stateTag, stateAttrName, stateAfterName, stateBeforeValue, stateAttr: + return true + } + return false +} + // delim is the delimiter that will end the current HTML attribute. type delim uint8 diff --git a/src/pkg/exp/template/html/escape.go b/src/pkg/exp/template/html/escape.go index 050746c1b2..28019f2525 100644 --- a/src/pkg/exp/template/html/escape.go +++ b/src/pkg/exp/template/html/escape.go @@ -583,7 +583,14 @@ func (e *escaper) escapeText(c context, n *parse.TextNode) context { // s, then returns the context after those tokens and the unprocessed suffix. func contextAfterText(c context, s []byte) (context, int) { if c.delim == delimNone { - return transitionFunc[c.state](c, s) + c1, i := tSpecialTagEnd(c, s) + if i == 0 { + // A special end tag (``) has been seen and + // all content preceding it has been consumed. + return c1, 0 + } + // Consider all content up to any end tag. + return transitionFunc[c.state](c, s[:i]) } i := bytes.IndexAny(s, delimEnds[c.delim]) diff --git a/src/pkg/exp/template/html/escape_test.go b/src/pkg/exp/template/html/escape_test.go index cf1c828002..84bf6b7a4a 100644 --- a/src/pkg/exp/template/html/escape_test.go +++ b/src/pkg/exp/template/html/escape_test.go @@ -814,7 +814,7 @@ func TestErrors(t *testing.T) { }, { `