Skip to content

Commit 8ae811a

Browse files
rolandshoemakergopherbot
authored andcommitted
html: properly handle end script tag in fragment mode
Change-Id: I10af60ce9aa6ffc2f2bc330026f9e4bc5cb30bb7 Reviewed-on: https://go-review.googlesource.com/c/net/+/781892 Auto-Submit: Roland Shoemaker <[email protected]> Reviewed-by: Nicholas Husin <[email protected]> LUCI-TryBot-Result: [email protected] <[email protected]> Reviewed-by: Nicholas Husin <[email protected]>
1 parent 3e9891d commit 8ae811a

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎html/parse_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ var testDataDirs = []string{"testdata/html5lib-tests/tree-construction/", "testd
246246

247247
func TestParser(t *testing.T) {
248248
skipTests := map[string]bool{
249-
"testdata/html5lib-tests/tree-construction/tests4.dat/8": true, // strange script case
250249
"testdata/html5lib-tests/tree-construction/webkit02.dat/22": true, // xml attribute sort & replace
251250
}
252251

‎html/token.go‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,22 @@ func NewTokenizerFragment(r io.Reader, contextTag string) *Tokenizer {
13001300
attrNames: make(map[string]bool),
13011301
}
13021302
if contextTag != "" {
1303+
// Per the "Parsing HTML Fragments" portion of the spec:
1304+
// For performance reasons, an implementation that does not report errors
1305+
// and that uses the actual state machine described in this specification
1306+
// directly could use the PLAINTEXT state instead of the RAWTEXT and script
1307+
// data states where those are mentioned in the list above. Except for
1308+
// rules regarding parse errors, they are equivalent, since there is no
1309+
// appropriate end tag token in the fragment case, yet they involve far
1310+
// fewer state transitions.
1311+
//
1312+
// As such we just set everything to plaintext, which makes some complex parsing
1313+
// cases somewhat simpler.
13031314
switch s := strings.ToLower(contextTag); s {
1304-
case "iframe", "noembed", "noframes", "noscript", "plaintext", "script", "style", "title", "textarea", "xmp":
1315+
case "title", "textarea":
13051316
z.rawTag = s
1317+
case "style", "xmp", "iframe", "noembed", "noframes", "script", "noscript", "plaintext":
1318+
z.rawTag = "plaintext"
13061319
}
13071320
}
13081321
return z

0 commit comments

Comments
 (0)