From 669b39927b7fb48bd7464fc2bb7497ed8c75efb6 Mon Sep 17 00:00:00 2001 From: Andrea Princic <48788808+Princic-1837592@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:09:31 +0100 Subject: [PATCH] Escape text inside entity when building unparsed text (#1156) --- pyrogram/parser/html.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/parser/html.py b/pyrogram/parser/html.py index 4afeea2b..c574e6ff 100644 --- a/pyrogram/parser/html.py +++ b/pyrogram/parser/html.py @@ -233,8 +233,10 @@ class HTML: while i < len(entities): i += recursive(i) + last_offset = entities_offsets[-1][1] # no need to sort, but still add entities starting from the end for entity, offset in reversed(entities_offsets): - text = text[:offset] + entity + text[offset:] + text = text[:offset] + entity + html.escape(text[offset:last_offset]) + text[last_offset:] + last_offset = offset return utils.remove_surrogates(text)