Fix aaee092 to correct entities' offsets on stripping

This commit is contained in:
Lonami Exo 2018-12-06 12:33:15 +01:00
parent 424079aa12
commit 40730e7862

View File

@ -1,5 +1,4 @@
"""Various helpers not related to the Telegram API itself""" """Various helpers not related to the Telegram API itself"""
import asyncio
import os import os
import struct import struct
from hashlib import sha1, sha256 from hashlib import sha1, sha256
@ -55,14 +54,19 @@ def strip_text(text, entities):
text = text[:-1] text = text[:-1]
while text and text[0].isspace(): while text and text[0].isspace():
e = entities[0] for i in reversed(range(len(entities))):
if e.offset == 0: e = entities[i]
if e.offset != 0:
e.offset -= 1
continue
if e.length == 1: if e.length == 1:
del entities[0] del entities[0]
if not entities: if not entities:
return text.lstrip() return text.lstrip()
else: else:
e.length -= 1 e.length -= 1
text = text[1:] text = text[1:]
return text return text