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

Commit 17ff62d

Browse files
committed
Fix a parse issue and get 100% test coverage
1 parent b34a585 commit 17ff62d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

html_tstring/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def handle_endtag(self, tag: str) -> None:
4444
if most_recent_closed and most_recent_closed.tag == tag:
4545
# Ignore this call; we've already closed it.
4646
return
47+
48+
if not self.stack:
4749
raise ValueError(f"Unexpected closing tag </{tag}> with no open element.")
4850

4951
element = self.stack.pop()

html_tstring/parser_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ def test_parse_unclosed_tag():
165165
_ = parse_html("<div>Unclosed")
166166

167167

168+
def test_parse_unexpected_closing_tag():
169+
with pytest.raises(ValueError):
170+
_ = parse_html("Unopened</div>")
171+
172+
168173
def test_parse_html_iter_preserves_chunks():
169174
chunks = [
170175
"<div>",

0 commit comments

Comments
 (0)