src/go/build/deps_test.go | 6 +++---
src/html/template/context.go | 14 ++++++++++++++
src/html/template/escape.go | 26 ++++++++++++++++++++++++++
src/html/template/escape_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
src/html/template/transition.go | 15 +++++++++++++++
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
index 08452c7b1d27f49820ac47a5daf8e3666a8df784..3e8fb9ea112d2f04a055d9256335b23e62256f1f 100644
--- a/src/go/build/deps_test.go
+++ b/src/go/build/deps_test.go
@@ -236,14 +236,14 @@ net/url, text/template/parse
< text/template
< internal/lazytemplate;
- encoding/json, html, text/template
- < html/template;
-
# regexp
FMT
< regexp/syntax
< regexp
< internal/lazyregexp;
+
+ encoding/json, html, text/template, regexp
+ < html/template;
# suffix array
encoding/binary, regexp
diff --git a/src/html/template/context.go b/src/html/template/context.go
index e07a0c4a027d06fd1ae74241fc50bd70a287dddc..7987713c65b614f209b1a0e36dcd65236c576676 100644
--- a/src/html/template/context.go
+++ b/src/html/template/context.go
@@ -174,6 +174,20 @@ }
return false
}
+// isInScriptLiteral returns true if s is one of the literal states within a
+// ",
}
+var (
+ // Per WHATWG HTML specification, section 4.12.1.3, there are extremely
+ // complicated rules for how to handle the set of opening tags " instead of "/*" or "//"
cs -= 1
}
b.Write(s[written:cs])
+ written = i1
+ }
+ if isInScriptLiteral(c.state) && containsSpecialScriptTag(s[i:i1]) {
+ b.Write(s[written:i])
+ b.Write(escapeSpecialScriptTags(s[i:i1]))
written = i1
}
if i == i1 && c.state == c1.state {
diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go
index f60c875927011df9e94874565e360759c79c39f4..8a4f62e92fae73ddc753ea4b5e7c14d3af3748e1 100644
--- a/src/html/template/escape_test.go
+++ b/src/html/template/escape_test.go
@@ -514,6 +514,21 @@ "",
"",
},
{
+ "Special tags in `,
+ ``,
+ },
+ {
+ "Special tags in `,
+ ``,
+ },
+ {
+ "Special tags in `,
+ ``,
+ },
+ {
"CSS comments",
"`,
@@ -1533,8 +1548,38 @@ ` should not
+ // cause us to exit the JS state.
`");`,
- context{state: stateText},
+ context{state: stateJS, element: elementScript},
+ },
+ {
+ ``,
+ context{state: stateJSDqStr, element: elementScript},
+ },
+ {
+ `");`,
+ context{state: stateJS, element: elementScript},
+ },
+ {
+ `let a = /`,
diff --git a/src/html/template/transition.go b/src/html/template/transition.go
index 12aa4c41fec7b3be5f67f7d268ce572e1b75f995..3d2a37cdd990119fbff5b4332f4151420dae7933 100644
--- a/src/html/template/transition.go
+++ b/src/html/template/transition.go
@@ -214,6 +214,11 @@ // tSpecialTagEnd is the context transition function for raw text and RCDATA
// element states.
func tSpecialTagEnd(c context, s []byte) (context, int) {
if c.element != elementNone {
+ // script end tags (" 0 && i+7 <= len(s) && bytes.Compare(bytes.ToLower(s[i-1:i+7]), []byte("