pyrofork icon indicating copy to clipboard operation
pyrofork copied to clipboard

UnicodeDecodeError in Str implementation

Open emv33 opened this issue 10 months ago • 0 comments

Checklist

  • [X] I am sure the error is coming from Pyrofork's code and not elsewhere
  • [X] I have searched in the issue tracker for similar bug reports, including closed ones
  • [X] I ran pip3 install -U git+https://github.com/Mayuri-Chan/pyrofork and reproduced the issue using the latest development version

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

emv33 avatar Apr 17 '24 15:04 emv33