Mayuri-Chan / pyrofork

Pyrogram fork with Adjustable web page preview, Quote Reply, Story & Topics Support, Mongodb session storage, and much more. go to https://pyrofork.wulan17.top/ for documentation.
https://pyrofork.wulan17.top
GNU Lesser General Public License v3.0
162 stars 78 forks source link

UnicodeDecodeError in Str implementation #65

Open emv33 opened 7 months ago

emv33 commented 7 months ago

Checklist

Description

There's a crash in message.text (which, btw, is not str - this is not stated in the documentation, which says message.text is a plain str)...

Steps to reproduce

Add the following message handler to the bot and then write this message anywhere the bot is:

🏳️‍🌈🏳️‍🌈

Code example

@app.on_message(group=-199)
async def test(client: pyrogram.client.Client, message: pyrogram.types.Message) -> None:
    print(message.text[:5])

Logs

[   dispatcher.py:342    handler_worker()] 'utf-16-le' codec can't decode bytes in position 10-11: unexpected end of data
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/pyrogram/dispatcher.py", line 329, in handler_worker
    await handler.callback(self.client, *args)
  File "/home/user/.local/lib/python3.10/site-packages/pyrogram/handlers/message_handler.py", line 151, in resolve_future_or_callback
    await self.original_callback(client, message, *args)
  File "/mnt/c/bot/handlers/test.py", line 38, in test
    print(message.text[:5])
  File "/home/user/.local/lib/python3.10/site-packages/pyrogram/types/messages_and_media/message.py", line 57, in __getitem__
    return parser_utils.remove_surrogates(parser_utils.add_surrogates(self)[item])
  File "/home/user/.local/lib/python3.10/site-packages/pyrogram/parser/utils.py", line 38, in remove_surrogates
    return text.encode("utf-16", "surrogatepass").decode("utf-16")
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 10-11: unexpected end of data