This repository was archived by the owner on Sep 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,15 @@ def handle_starttag(
3535 def handle_endtag (self , tag : str ) -> None :
3636 if tag in VOID_ELEMENTS :
3737 # Special case: handle Python issue #69445 (see comment above).
38+ most_recent_closed = self .get_most_recent_closed_element ()
39+ if most_recent_closed and most_recent_closed .tag == tag :
40+ # Ignore this call; we've already closed it.
41+ return
3842 open_element = self .get_open_element ()
3943 if open_element and open_element .tag == tag :
4044 _ = self .stack .pop ()
4145 self .append_child (open_element )
4246 return
43- most_recent_closed = self .get_most_recent_closed_element ()
44- if most_recent_closed and most_recent_closed .tag == tag :
45- # Ignore this call; we've already closed it.
46- return
4747
4848 if not self .stack :
4949 raise ValueError (f"Unexpected closing tag </{ tag } > with no open element." )
Original file line number Diff line number Diff line change @@ -170,6 +170,16 @@ def test_parse_unexpected_closing_tag():
170170 _ = parse_html ("Unopened</div>" )
171171
172172
173+ def test_nested_self_closing_tags ():
174+ node = parse_html ("<div></div><br>" )
175+ assert node == Fragment (
176+ children = [
177+ Element ("div" ),
178+ Element ("br" ),
179+ ]
180+ )
181+
182+
173183def test_parse_html_iter_preserves_chunks ():
174184 chunks = [
175185 "<div>" ,
You can’t perform that action at this time.
0 commit comments