@@ -136,7 +136,7 @@ func (p *parser) indexOfElementInScope(s scope, matchTags ...a.Atom) int {
136136 return - 1
137137 }
138138 default :
139- panic ("unreachable" )
139+ panic (fmt . Sprintf ( "html: internal error: indexOfElementInScope unknown scope: %d" , s ) )
140140 }
141141 }
142142 switch s {
@@ -179,7 +179,7 @@ func (p *parser) clearStackToContext(s scope) {
179179 return
180180 }
181181 default :
182- panic ("unreachable" )
182+ panic (fmt . Sprintf ( "html: internal error: clearStackToContext unknown scope: %d" , s ) )
183183 }
184184 }
185185}
@@ -1678,7 +1678,7 @@ func inTableBodyIM(p *parser) bool {
16781678 return inTableIM (p )
16791679}
16801680
1681- // Section 12 .2.6.4.14.
1681+ // Section 13 .2.6.4.14.
16821682func inRowIM (p * parser ) bool {
16831683 switch p .tok .Type {
16841684 case StartTagToken :
@@ -1690,7 +1690,9 @@ func inRowIM(p *parser) bool {
16901690 p .im = inCellIM
16911691 return true
16921692 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 ()
16941696 p .im = inTableBodyIM
16951697 return false
16961698 }
@@ -1700,22 +1702,28 @@ func inRowIM(p *parser) bool {
17001702 case EndTagToken :
17011703 switch p .tok .DataAtom {
17021704 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 ()
17041708 p .im = inTableBodyIM
17051709 return true
17061710 }
17071711 // Ignore the token.
17081712 return true
17091713 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 ()
17111717 p .im = inTableBodyIM
17121718 return false
17131719 }
17141720 // Ignore the token.
17151721 return true
17161722 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
17191727 return false
17201728 }
17211729 // Ignore the token.
@@ -2222,16 +2230,20 @@ func parseForeignContent(p *parser) bool {
22222230 p .acknowledgeSelfClosingTag ()
22232231 }
22242232 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+ }
22252237 for i := len (p .oe ) - 1 ; i >= 0 ; i -- {
2226- if p .oe [i ].Namespace == "" {
2227- return p .im (p )
2228- }
22292238 if strings .EqualFold (p .oe [i ].Data , p .tok .Data ) {
22302239 p .oe = p .oe [:i ]
2240+ return true
2241+ }
2242+ if i > 0 && p .oe [i - 1 ].Namespace == "" {
22312243 break
22322244 }
22332245 }
2234- return true
2246+ return p . im ( p )
22352247 default :
22362248 // Ignore the token.
22372249 }
0 commit comments