Skip to content

Commit 46ff47d

Browse files
authored
Merge pull request #20 from Earth-Online/master
fix #19 missing start tag error
2 parents 9456562 + b8e5a6b commit 46ff47d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

telegraph/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def handle_endtag(self, tag):
8383
if tag in VOID_ELEMENTS:
8484
return
8585

86+
if not len(self.parent_nodes):
87+
raise InvalidHTML('"{}" missing start tag'.format(
88+
tag
89+
))
90+
8691
self.current_nodes = self.parent_nodes.pop()
8792

8893
last_node = self.current_nodes[-1]

tests/test_html_converter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'attrs': {'href': 'https://telegra.ph/'},
2020
'children': ['Test link</a>']
2121
}]
22-
},
22+
},
2323
{'tag': 'figure', 'children': [
2424
{'tag': 'img', 'attrs': {'src': '/file/6c2ecfdfd6881d37913fa.png'}},
2525
{'tag': 'figcaption'}
@@ -45,6 +45,8 @@
4545
]},
4646
]
4747

48+
HTML_NO_STARTTAG = "</a><h1></h1>"
49+
4850

4951
class TestHTMLConverter(TestCase):
5052
def test_html_to_nodes(self):
@@ -130,3 +132,7 @@ def test_clear_whitespace_nodes(self):
130132
]
131133

132134
self.assertEqual(clear_whitespace_nodes(nodes)[0], expected)
135+
136+
def test_no_starttag_node(self):
137+
with self.assertRaises(InvalidHTML):
138+
html_to_nodes(HTML_NO_STARTTAG)

0 commit comments

Comments
 (0)