From b3f849df762df799b43dcde109ef6516a1a50281 Mon Sep 17 00:00:00 2001 From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com> Date: Thu, 3 Feb 2022 15:26:17 +0100 Subject: [PATCH] Fix entities unparsing in other scenarios (#892) --- pyrogram/parser/html.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index 81c761ac..b1ce5c5d 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -174,8 +174,17 @@ class HTML: entities_offsets.append((start_tag, start,)) entities_offsets.append((end_tag, end,)) + + entities_offsets = map( + lambda x: x[1], + sorted( + enumerate(entities_offsets), + key = lambda x: (x[1][1], x[0]), + reverse = True + ) + ) - for entity, offset in reversed(entities_offsets): + for entity, offset in entities_offsets: text = text[:offset] + entity + text[offset:] return utils.remove_surrogates(text)