mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-13 04:56:35 +03:00
Fix parsers misbehaving with None text
This commit is contained in:
parent
92b6e857a4
commit
2fb5215f5f
|
@ -121,6 +121,9 @@ def parse(html):
|
||||||
:param message: the message with HTML to be parsed.
|
:param message: the message with HTML to be parsed.
|
||||||
:return: a tuple consisting of (clean message, [message entities]).
|
:return: a tuple consisting of (clean message, [message entities]).
|
||||||
"""
|
"""
|
||||||
|
if not html:
|
||||||
|
return html, []
|
||||||
|
|
||||||
parser = HTMLToTelegramParser()
|
parser = HTMLToTelegramParser()
|
||||||
parser.feed(_add_surrogate(html))
|
parser.feed(_add_surrogate(html))
|
||||||
return _del_surrogate(parser.text), parser.entities
|
return _del_surrogate(parser.text), parser.entities
|
||||||
|
@ -135,7 +138,7 @@ def unparse(text, entities):
|
||||||
:param entities: the MessageEntity's applied to the text.
|
:param entities: the MessageEntity's applied to the text.
|
||||||
:return: a HTML representation of the combination of both inputs.
|
:return: a HTML representation of the combination of both inputs.
|
||||||
"""
|
"""
|
||||||
if not entities:
|
if not text or not entities:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
text = _add_surrogate(text)
|
text = _add_surrogate(text)
|
||||||
|
|
|
@ -36,6 +36,9 @@ def parse(message, delimiters=None, url_re=None):
|
||||||
:param url_re: the URL bytes regex to be used. Must have two groups.
|
:param url_re: the URL bytes regex to be used. Must have two groups.
|
||||||
:return: a tuple consisting of (clean message, [message entities]).
|
:return: a tuple consisting of (clean message, [message entities]).
|
||||||
"""
|
"""
|
||||||
|
if not message:
|
||||||
|
return message, []
|
||||||
|
|
||||||
if url_re is None:
|
if url_re is None:
|
||||||
url_re = DEFAULT_URL_RE
|
url_re = DEFAULT_URL_RE
|
||||||
elif isinstance(url_re, str):
|
elif isinstance(url_re, str):
|
||||||
|
@ -137,7 +140,7 @@ def unparse(text, entities, delimiters=None, url_fmt=None):
|
||||||
:param entities: the MessageEntity's applied to the text.
|
:param entities: the MessageEntity's applied to the text.
|
||||||
:return: a markdown-like text representing the combination of both inputs.
|
:return: a markdown-like text representing the combination of both inputs.
|
||||||
"""
|
"""
|
||||||
if not entities:
|
if not text or not entities:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
if not delimiters:
|
if not delimiters:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user