-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Catch json_data decode errors #1072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes the case where non-utf8 data would cause an exception and halt the dispatcher. See https://t.me/pythontelegrambotgroup/129353 for more info. Note that the telegram docs at https://core.telegram.org/bots/api#callbackquery warn about this specific case ("Be aware that a bad client can send arbitrary data in this field.").
|
Thanks a lot for your contribution @udf The bug and fix look good, but it would be great to have a test to ensure we won't have regressions on this in the future. I see you are a first-time contributor, would you like to add your name to the |
|
How does one write tests for a single line change like this…? There should have been tests before the change, testing random bytes. |
|
@Lonami If we had tests before, we would have caught the bug. Now we need a test (that would fail with the old code) to prevent this bug from happening again in case the code is changed in the future. The size of the diff doesn't really matter. |
|
@udf A good test case would be to show that the correct exception is raised for a callback query that contains bytes that can't be decoded using the utf8 encoding |
|
I feel like we can open a separate issue to track that, this should be merged ASAP as it brings down any bots using the library. Unless you restart them automatically they will be down until you find out. |
|
@jh0ker I don't have the time right now to figure out how to write a test. Perhaps someone else can do it, so we can get this merged quicker? |
|
Closing this because apparently critical bug fixes aren't important enough. |
|
I'm actually in the process of writing unit tests right now. If you don't want your commits merged, I'll commit the fix myself. Otherwise, feel free to reopen this PR. |
|
Thanks, we're just glad it will be fixed one way or another. |
Fixes the case where non-utf8 data would cause an exception and halt the dispatcher. See https://t.me/pythontelegrambotgroup/129353 for more info.
Note that the telegram docs at https://core.telegram.org/bots/api#callbackquery warn about this specific case ("Be aware that a bad client can send arbitrary data in this field.").