Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit f01502e

Browse files
committed
Add a couple new parser test cases.
1 parent 17ff62d commit f01502e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

html_tstring/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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.")

html_tstring/parser_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
173183
def test_parse_html_iter_preserves_chunks():
174184
chunks = [
175185
"<div>",

0 commit comments

Comments
 (0)