@@ -136,7 +136,7 @@ func (p *parser) indexOfElementInScope(s scope, matchTags ...a.Atom) int {
136
136
return - 1
137
137
}
138
138
default :
139
- panic ("unreachable" )
139
+ panic (fmt . Sprintf ( "html: internal error: indexOfElementInScope unknown scope: %d" , s ) )
140
140
}
141
141
}
142
142
switch s {
@@ -179,7 +179,7 @@ func (p *parser) clearStackToContext(s scope) {
179
179
return
180
180
}
181
181
default :
182
- panic ("unreachable" )
182
+ panic (fmt . Sprintf ( "html: internal error: clearStackToContext unknown scope: %d" , s ) )
183
183
}
184
184
}
185
185
}
@@ -1678,7 +1678,7 @@ func inTableBodyIM(p *parser) bool {
1678
1678
return inTableIM (p )
1679
1679
}
1680
1680
1681
- // Section 12 .2.6.4.14.
1681
+ // Section 13 .2.6.4.14.
1682
1682
func inRowIM (p * parser ) bool {
1683
1683
switch p .tok .Type {
1684
1684
case StartTagToken :
@@ -1690,7 +1690,9 @@ func inRowIM(p *parser) bool {
1690
1690
p .im = inCellIM
1691
1691
return true
1692
1692
case a .Caption , a .Col , a .Colgroup , a .Tbody , a .Tfoot , a .Thead , a .Tr :
1693
- if p .popUntil (tableScope , a .Tr ) {
1693
+ if p .elementInScope (tableScope , a .Tr ) {
1694
+ p .clearStackToContext (tableRowScope )
1695
+ p .oe .pop ()
1694
1696
p .im = inTableBodyIM
1695
1697
return false
1696
1698
}
@@ -1700,22 +1702,28 @@ func inRowIM(p *parser) bool {
1700
1702
case EndTagToken :
1701
1703
switch p .tok .DataAtom {
1702
1704
case a .Tr :
1703
- if p .popUntil (tableScope , a .Tr ) {
1705
+ if p .elementInScope (tableScope , a .Tr ) {
1706
+ p .clearStackToContext (tableRowScope )
1707
+ p .oe .pop ()
1704
1708
p .im = inTableBodyIM
1705
1709
return true
1706
1710
}
1707
1711
// Ignore the token.
1708
1712
return true
1709
1713
case a .Table :
1710
- if p .popUntil (tableScope , a .Tr ) {
1714
+ if p .elementInScope (tableScope , a .Tr ) {
1715
+ p .clearStackToContext (tableRowScope )
1716
+ p .oe .pop ()
1711
1717
p .im = inTableBodyIM
1712
1718
return false
1713
1719
}
1714
1720
// Ignore the token.
1715
1721
return true
1716
1722
case a .Tbody , a .Tfoot , a .Thead :
1717
- if p .elementInScope (tableScope , p .tok .DataAtom ) {
1718
- p .parseImpliedToken (EndTagToken , a .Tr , a .Tr .String ())
1723
+ if p .elementInScope (tableScope , p .tok .DataAtom ) && p .elementInScope (tableScope , a .Tr ) {
1724
+ p .clearStackToContext (tableRowScope )
1725
+ p .oe .pop ()
1726
+ p .im = inTableBodyIM
1719
1727
return false
1720
1728
}
1721
1729
// Ignore the token.
@@ -2222,16 +2230,20 @@ func parseForeignContent(p *parser) bool {
2222
2230
p .acknowledgeSelfClosingTag ()
2223
2231
}
2224
2232
case EndTagToken :
2233
+ if strings .EqualFold (p .oe [len (p .oe )- 1 ].Data , p .tok .Data ) {
2234
+ p .oe = p .oe [:len (p .oe )- 1 ]
2235
+ return true
2236
+ }
2225
2237
for i := len (p .oe ) - 1 ; i >= 0 ; i -- {
2226
- if p .oe [i ].Namespace == "" {
2227
- return p .im (p )
2228
- }
2229
2238
if strings .EqualFold (p .oe [i ].Data , p .tok .Data ) {
2230
2239
p .oe = p .oe [:i ]
2240
+ return true
2241
+ }
2242
+ if i > 0 && p .oe [i - 1 ].Namespace == "" {
2231
2243
break
2232
2244
}
2233
2245
}
2234
- return true
2246
+ return p . im ( p )
2235
2247
default :
2236
2248
// Ignore the token.
2237
2249
}
0 commit comments