-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
HTML tag in user's profile name makes problem in parse html #4257
Comments
as i got to know that i should use a new code which will enlarged the fucntionality of the User class, https://t.me/pythontelegrambottalk/254801, |
i am saying about this type of type hint, as after i defines, |
Thanks for reaching out and taking the time to write up this feature request. In the future, when writing comments on GitHub threads (not only on the ptb repositories but everywher), please post code and traceback as monospaced text rather than taking screenshots. You can highlight sections of that by adding comments. We have considered your feature request in the dev team and have decided to reject it for two reasions:
I will hence reject & close this feature request. Please refrain elaborating your request any further. |
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
Hello Admins Here, Please don't scold me much much, please Listen to me with♥️ 💖💝
See My Issue which is related to HTML tags in the Telegram Profile User Name, this issue comes when the user name contains invalid character like < >,
this makes the normal PTB beheaviour to throw a telegram.BadRequest Error,
see the image here
You can see the code example in this PTB Example code where i have write the full ready to use main.py code, so that you can fully run this main.py just by replacing the Bot Token for testing purpose.
Link of the main.py code is: https://github.com/RanaUniverse/ptb_02_html/blob/main/main.py
As i understand, i found when a user name contains < or > or both the problem occurs in the line 56 in the main.py, which got replaced
user.full_name = name which contains < or >
as a result the parse_mode = "HTML" not support the < with different character,
see as a example i checked with this bot testing, and as my code says when i will send /start to bot, it will send my my name in bold + underline formatting as a reply as you can see the image below that the response shows here after i rename my account several time without any < or > , and the bot response to me without any error in the terminal.
as you can see when my name has not < > the response was with bold and underline and at the moment i add < > in my profile name then bot stops response me and it cause shows the error in the temrinal as i mentioned above in the first image.
So here what i means to say is, in most case we use
then to get the user full name we use
user.full_name
and then when we want some design in the reply text we directly use this inside text parameter and pass parsemode = "HTML",so most of the cases user's name contains no < & > so it does not throw any error, so it looks like our bold+underline design will work completely fines for all cases.
But as the example i shows you in this upper i described that if a user name contains < > it will show error, and my code flow of execution will breake, so to solve this problem we need to use
import html
html.escape(user.full_name)
But writing this each time in all the other places where i used the users name in the text i need to import and use this html library in all the places,
so what i means to say that we need a new property which will use the html.escape in background and return the full name without < & >,
Thanks For teach me this how to use the escape to use proper functionality as i expected,
Describe the solution you'd like
So as i think to add a new property in the user class in this section , like this:::
C:\Users\RanaUniverse\AppData\Local\Programs\Python\Python312\Lib\site-packages\telegram_user.py
in this module of the PTB library if we will make a new class property like this, so we can directly call this function using the user class object and got no error,
i checked with change it in the source code in my vs code directly and use it and got proper result
and below image you can see after i add a new property and then use it in my start funciton you see the below image which shows correct response to user even if the user name contains the unsupported tags
so what i means to say that if you will add this new property in this PTB, it can help us a lot by callig this new property all time, without we need to take care of user name contains any invalid character or not,
please look into the matter,
Describe alternatives you've considered
I want You will see into the matter, and having a new property for this, will help us in future, without making any problem to our existing PTB code
Additional context
Please dont say to use me
in all the lines rather it will easy if we use directly
user.full_name_html
like this or any other related property name
The text was updated successfully, but these errors were encountered: