Skip to content

Commit

Permalink
html: fix wrong comparison in foster parenting algorithm
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
namusyaka authored and nigeltao committed Aug 26, 2018
1 parent 4bcd98c commit 8a410e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion html/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions html/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions html/testdata/webkit/template.dat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1297,3 +1311,16 @@
| content
| "Foo"
| <body>

#data
<template><a><table><a>
#errors
#document
| <html>
| <head>
| <template>
| content
| <a>
| <a>
| <table>
| <body>

0 comments on commit 8a410e7

Please sign in to comment.