Repository navigation
Treat RichText strings as JSON only when they parse to an object - #2635
Conversation
Plain text that happens to parse as JSON, like a "[56]" superscript footnote mark, was turned into a list and then crashed with 'pop expected at most 1 argument, got 2'. Fixes eternnoir#2634
|
I assumed that https://core.telegram.org/bots/api#richtext
means array in data... Looks you are right: "Array of [RichText]" in fact is also encoded as json... |
|
Mmm. I remebered the reason of having this condition.
this is also a valid JSON. Thus due to the problem arized by Telegram who gives us "...it can be either a String for plain text,..." the way to detect if string is JSON or not is quite unsolvable... Thus I supposed that
in json string. I cannot proof this. If this suggestion is wrong - we can apply your fix. If not - we definitely cannot. |
|
An Array of RichText doesn't reach A string like |
|
Okay, looks you are right. I'll check a bit more and will proceed. Thank you. |
Description
Fixes #2634.
RichText.de_json()treated a plain-text string as JSON whenever it looked like a JSON object or array and parsed. A superscript footnote mark like"[56]"(common in Wikipedia-sourced rich messages) parses to the list[56]. It then went on tocheck_json()andobj.pop('type', None)on that list, and polling failed with:Now only a string that parses to a JSON object is handled as a serialized
RichText. Anything else ("[56]","[]", numbers,"null", invalid JSON) is returned as plain text, as the docs describe ("can be either a String for plain text…"). A JSON array string never worked before either: it hit the samepopon a list. Real arrays of rich text arrive as lists and still go through the existing list branch.Describe your tests
New
test_json_richtext_plain_text_that_looks_like_json:"[56]"deserializes toRichTextUrl→RichTextSuperscriptwith text"[56]";"[56]","[]","{}x","123","null"and'["a", "b"]'passed directly come back unchanged.It fails before the change and passes after it.
pytest tests/test_types.py: 266 passed.Python version: 3.12
OS: Windows 11
Checklist:
telebot/types.py)