Closed Rongronggg9 closed 2 years ago
Thanks for the detailed report. I agree your choices are the most sensible (and its implementation will have no visible changes to end-users, other than "it works like before").
I am not sure if I should add
ENTITY_BOUNDS_INVALID
as a new exception
Yes, the errors.csv
aims to document all seen errors (you could still trigger this one using raw API). It's even used by other people, so it's good we keep it up to date.
Yes, the
errors.csv
aims to document all seen errors (you could still trigger this one using raw API). It's even used by other people, so it's good we keep it up to date.
Sure! I will create another PR to add this. Which branch should it point to then? v1.24
or master
? Or both by creating 2 PRs?
No, v1.24 only is fine for now.
Ah we actually fixed this before but I didn't close the issue right? That'd explain why I couldn't reproduce it. Anyway the above commit should work even for user-provided parsers so I'm closing this now. Thanks!
Yes, the issue has been fixed. And I also failed to remember to close it, lol. I backported my PR for some days and reverted the backport commit after upgrading to v1.25. I've never seen this bug from then on.
Formerly, Telegram simply ignored 0-length
MessageEntity
, but several days before, Telegram has silently changed its server-side behavior to throw anRPCError 400: ENTITY_BOUNDS_INVALID
. However, the Markdown and HTML parsers of Telethon still produce 0-lengthMessageEntity
if the user input does have empty tags.A typical use case (https://github.com/Rongronggg9/RSS-to-Telegram-Bot/blob/15aef44b6e9b870ec9411398cb83ccb8f38acf68/src/command/administration.py#L17-L34) that can reproduce this issue (
value
can be an empty string, which is intended):I consider there are 3 solutions:
MessageEntity
(or even all invalid ones) before returning the parse result.I'd rather prefer 1 because:
f-string
,str.format()
,%
operator, or other templating methods are popular. They usually produce empty tags which are intended (at least in my use case, there are several templates that produce intended empty tags, one of which has been shown before).Obviously, this is not a bug of Telethon, but I wish Telethon could "fix" it urgently since the change has a wide influence but the use case is common.
I consider there are 2 possible "fixes":
helpers.strip_text()
to delete themI'd rather prefer 2 because:
I will submit a PR to the
v1.24
branch to fix it according to https://github.com/LonamiWebs/Telethon/issues/3880#issuecomment-1190811979.I am not sure if I should add
ENTITY_BOUNDS_INVALID
as a new exception sincev1
should not receive new features that is not necessary according to the same context.