Skip to content

Commit

Permalink
html: don't set im if <template> doesn't have HTML namespace
Browse files Browse the repository at this point in the history
If there are nested <template> elements and the <template> node isn't in HTML namespace,
couldn't continue to parse documents correctly.
By this patch, it makes the <template> which is in math namespace be skipped on
resetting insertion mode.

Fixes golang/go#27702

Change-Id: I6eacdb98fe29eb3c61781afca5bc4d83e72ba4ed
Reviewed-on: https://go-review.googlesource.com/136875
Reviewed-by: Nigel Tao <nigeltao@golang.org>
  • Loading branch information
namusyaka authored and nigeltao committed Sep 25, 2018
1 parent 2f5d238 commit cf3bd58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions html/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ func (p *parser) resetInsertionMode() {
case a.Table:
p.im = inTableIM
case a.Template:
// TODO: remove this divergence from the HTML5 spec.
if n.Namespace != "" {
continue
}
p.im = p.templateStack.top()
case a.Head:
// TODO: remove this divergence from the HTML5 spec.
Expand Down
13 changes: 13 additions & 0 deletions html/testdata/go/template.dat
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@
| content
| <tbody>
| <body>

#data
<math><template><mo><template>
#errors
#document
| <html>
| <head>
| <body>
| <math math>
| <math template>
| <math mo>
| <template>
| content

0 comments on commit cf3bd58

Please sign in to comment.