Strip 0-length message entities

Closes #3884.
This commit is contained in:
Lonami Exo 2022-09-20 13:12:01 +02:00
parent 7cac3668d6
commit 363c2604df

View File

@ -90,7 +90,12 @@ class MessageParseMethods:
for i in reversed(range(len(msg_entities))): for i in reversed(range(len(msg_entities))):
e = msg_entities[i] e = msg_entities[i]
if isinstance(e, types.MessageEntityTextUrl): if not e.length:
# 0-length MessageEntity is no longer valid #3884.
# Because the user can provide their own parser (with reasonable 0-length
# entities), strip them here rather than fixing the built-in parsers.
del msg_entities[i]
elif isinstance(e, types.MessageEntityTextUrl):
m = re.match(r'^@|\+|tg://user\?id=(\d+)', e.url) m = re.match(r'^@|\+|tg://user\?id=(\d+)', e.url)
if m: if m:
user = int(m.group(1)) if m.group(1) else e.url user = int(m.group(1)) if m.group(1) else e.url