2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-27 20:37:54 +00:00

Fix HTML parsing breaking with no tags

This commit is contained in:
Dan 2019-06-24 13:36:27 +02:00
parent 8e0182633f
commit cac0bcabf9

View File

@ -93,7 +93,10 @@ class Parser(HTMLParser):
self.text += data self.text += data
def handle_endtag(self, tag): def handle_endtag(self, tag):
start_tag = self.tags.pop() try:
start_tag = self.tags.pop()
except IndexError:
return
if start_tag != tag: if start_tag != tag:
line, offset = self.getpos() line, offset = self.getpos()
@ -113,6 +116,7 @@ class HTML:
def parse(self, text: str): def parse(self, text: str):
text = utils.add_surrogates(str(text or "").strip()) text = utils.add_surrogates(str(text or "").strip())
text = "<p>{}</p>".format(text)
parser = Parser(self.client) parser = Parser(self.client)
parser.feed(text) parser.feed(text)