Browse Source

html: fix wrong comparison in foster parenting algorithm

Fixes golang/go#23071

Change-Id: I383e13bfd87e32ffb775dff54c46b66b090e5017
Reviewed-on: https://go-review.googlesource.com/131475
Run-TryBot: Kunpei Sakai <namusyaka@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Kunpei Sakai 7 years ago
parent
commit
8a410e7b63
3 changed files with 29 additions and 1 deletions
  1. 1 1
      html/parse.go
  2. 1 0
      html/parse_test.go
  3. 27 0
      html/testdata/webkit/template.dat

+ 1 - 1
html/parse.go

@@ -255,7 +255,7 @@ func (p *parser) fosterParent(n *Node) {
 		}
 	}
 
-	if template != nil && (table == nil || j < i) {
+	if template != nil && (table == nil || j > i) {
 		template.AppendChild(n)
 		return
 	}

+ 1 - 0
html/parse_test.go

@@ -329,6 +329,7 @@ var renderTestBlacklist = map[string]bool{
 	`<a href="blah">aba<table><a href="foo">br<tr><td></td></tr>x</table>aoe`: true,
 	`<a><table><a></table><p><a><div><a>`:                                     true,
 	`<a><table><td><a><table></table><a></tr><a></table><a>`:                  true,
+	`<template><a><table><a>`:                                                 true,
 	// A similar reparenting situation involving <nobr>:
 	`<!DOCTYPE html><body><b><nobr>1<table><nobr></b><i><nobr>2<nobr></i>3`: true,
 	// A <plaintext> element is reparented, putting it before a table.

+ 27 - 0
html/testdata/webkit/template.dat

@@ -1130,6 +1130,20 @@
 |             <select>
 |   <body>
 
+#data
+<template><template><table>Foo
+#errors
+#document
+| <html>
+|   <head>
+|     <template>
+|       content
+|         <template>
+|           content
+|             "Foo"
+|             <table>
+|   <body>
+
 #data
 <template><template><frame>
 #errors
@@ -1297,3 +1311,16 @@
 |       content
 |         "Foo"
 |   <body>
+
+#data
+<template><a><table><a>
+#errors
+#document
+| <html>
+|   <head>
+|     <template>
+|       content
+|         <a>
+|           <a>
+|           <table>
+|   <body>