src/pkg/exp/template/html/context.go | 9 +++++++++ src/pkg/exp/template/html/escape.go | 9 ++++++++- src/pkg/exp/template/html/escape_test.go | 2 +- src/pkg/exp/template/html/html.go | 18 ++++++++++++------ src/pkg/exp/template/html/html_test.go | 1 + src/pkg/exp/template/html/transition.go | 106 +++++++++++++++-------------------------------------- diff --git a/src/pkg/exp/template/html/context.go b/src/pkg/exp/template/html/context.go index 57d44938ca66169305fb71a06f1beb5b0d0e307f..de073f134a388d49ef489654c8c12a7c9af07ded 100644 --- a/src/pkg/exp/template/html/context.go +++ b/src/pkg/exp/template/html/context.go @@ -175,6 +175,15 @@ } 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 050746c1b2a46e5fce93f53e5e4c5b8058cbf93a..28019f252522c84053c76e7f1b6c6f45a102ca1f 100644 --- a/src/pkg/exp/template/html/escape.go +++ b/src/pkg/exp/template/html/escape.go @@ -583,7 +583,14 @@ // contextAfterText starts in context c, consumes some tokens from the front of // 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 cf1c8280028c9d5e2fc1969e9a2b6635e48202da..84bf6b7a4ab67174a0e03e17407da3977109c03d 100644 --- a/src/pkg/exp/template/html/escape_test.go +++ b/src/pkg/exp/template/html/escape_test.go @@ -814,7 +814,7 @@ `unfinished escape sequence in JS string: "Hello\\, World\\"`, }, { `