From 75d99fbb53c1bb7d46f9b9909c056b6e00eab4d8 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 15 Feb 2018 11:52:46 +0100 Subject: [PATCH] Fix HTML entity parsing failing when needing surrogates --- telethon/extensions/html.py | 23 +++++++++++++++++++---- telethon/extensions/markdown.py | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/telethon/extensions/html.py b/telethon/extensions/html.py index 8cd170cb..bcbd13cc 100644 --- a/telethon/extensions/html.py +++ b/telethon/extensions/html.py @@ -1,9 +1,10 @@ """ Simple HTML -> Telegram entity parser. """ +import struct +from collections import deque from html import escape, unescape from html.parser import HTMLParser -from collections import deque from ..tl.types import ( MessageEntityBold, MessageEntityItalic, MessageEntityCode, @@ -12,6 +13,18 @@ from ..tl.types import ( ) +# Helpers from markdown.py +def _add_surrogate(text): + return ''.join( + ''.join(chr(y) for y in struct.unpack('