mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 03:22:29 +00:00
Fix unparsing malformed entities, bump v1.10.10
This commit is contained in:
@@ -174,10 +174,12 @@ def unparse(text: str, entities: Iterable[TypeMessageEntity], _offset: int = 0,
|
||||
# Otherwise we would end up with malformed text and fail to encode.
|
||||
# For example of bad input: "Hi \ud83d\ude1c"
|
||||
# https://en.wikipedia.org/wiki/UTF-16#U+010000_to_U+10FFFF
|
||||
if '\ud800' <= text[relative_offset] <= '\udfff':
|
||||
while (relative_offset < _length
|
||||
and '\ud800' <= text[relative_offset] <= '\udfff'):
|
||||
relative_offset += 1
|
||||
|
||||
if '\ud800' <= text[relative_offset + length] <= '\udfff':
|
||||
while (relative_offset + length < _length
|
||||
and '\ud800' <= text[relative_offset + length] <= '\udfff'):
|
||||
length += 1
|
||||
|
||||
entity_text = unparse(text=text[relative_offset:relative_offset + length],
|
||||
@@ -222,7 +224,7 @@ def unparse(text: str, entities: Iterable[TypeMessageEntity], _offset: int = 0,
|
||||
skip_entity = True
|
||||
last_offset = relative_offset + (0 if skip_entity else length)
|
||||
|
||||
if last_offset < len(text) and '\ud800' <= text[last_offset] <= '\udfff':
|
||||
while last_offset < _length and '\ud800' <= text[last_offset] <= '\udfff':
|
||||
last_offset += 1
|
||||
|
||||
html.append(escape(text[last_offset:]))
|
||||
|
Reference in New Issue
Block a user