diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py
index 8a7063e5..d9a8d368 100644
--- a/pyrogram/parser/html.py
+++ b/pyrogram/parser/html.py
@@ -140,6 +140,9 @@ class HTML:
entities.append(entity)
+ # Remove zero-length entities
+ entities = list(filter(lambda x: x.length > 0, entities))
+
return {
"message": utils.remove_surrogates(parser.text),
"entities": sorted(entities, key=lambda e: e.offset)
@@ -156,13 +159,21 @@ class HTML:
start = entity.offset
end = start + entity.length
- if entity_type in (MessageEntityType.BOLD, MessageEntityType.ITALIC, MessageEntityType.UNDERLINE,
- MessageEntityType.STRIKETHROUGH):
+ if entity_type in (
+ MessageEntityType.BOLD,
+ MessageEntityType.ITALIC,
+ MessageEntityType.UNDERLINE,
+ MessageEntityType.STRIKETHROUGH,
+ ):
name = entity_type.name[0].lower()
start_tag = f"<{name}>"
end_tag = f"{name}>"
- elif entity_type in (MessageEntityType.CODE, MessageEntityType.PRE, MessageEntityType.BLOCKQUOTE,
- MessageEntityType.SPOILER):
+ elif entity_type in (
+ MessageEntityType.CODE,
+ MessageEntityType.PRE,
+ MessageEntityType.BLOCKQUOTE,
+ MessageEntityType.SPOILER,
+ ):
name = entity_type.name.lower()
start_tag = f"<{name}>"
end_tag = f"{name}>"
diff --git a/pyrogram/utils.py b/pyrogram/utils.py
index d5862d1a..b6a8d6bf 100644
--- a/pyrogram/utils.py
+++ b/pyrogram/utils.py
@@ -48,8 +48,10 @@ def get_input_media_from_file_id(
try:
decoded = FileId.decode(file_id)
except Exception:
- raise ValueError(f'Failed to decode "{file_id}". The value does not represent an existing local file, '
- f'HTTP URL, or valid file id.')
+ raise ValueError(
+ f'Failed to decode "{file_id}". The value does not represent an existing local file, '
+ f"HTTP URL, or valid file id."
+ )
file_type = decoded.file_type
@@ -82,7 +84,11 @@ def get_input_media_from_file_id(
raise ValueError(f"Unknown file id: {file_id}")
-async def parse_messages(client, messages: "raw.types.messages.Messages", replies: int = 1) -> List["types.Message"]:
+async def parse_messages(
+ client,
+ messages: "raw.types.messages.Messages",
+ replies: int = 1
+) -> List["types.Message"]:
users = {i.id: i for i in messages.users}
chats = {i.id: i for i in messages.chats}
@@ -260,8 +266,10 @@ def xor(a: bytes, b: bytes) -> bytes:
return bytes(i ^ j for i, j in zip(a, b))
-def compute_password_hash(algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow,
- password: str) -> bytes:
+def compute_password_hash(
+ algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow,
+ password: str
+) -> bytes:
hash1 = sha256(algo.salt1 + password.encode() + algo.salt1)
hash2 = sha256(algo.salt2 + hash1 + algo.salt2)
hash3 = hashlib.pbkdf2_hmac("sha512", hash2, algo.salt1, 100000)
@@ -270,7 +278,10 @@ def compute_password_hash(algo: raw.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACS
# noinspection PyPep8Naming
-def compute_password_check(r: raw.types.account.Password, password: str) -> raw.types.InputCheckPasswordSRP:
+def compute_password_check(
+ r: raw.types.account.Password,
+ password: str
+) -> raw.types.InputCheckPasswordSRP:
algo = r.current_algo
p_bytes = algo.p