Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Fix filters.Mention matching other users without username - #5385

Open
Enesuygurs wants to merge 1 commit into
python-telegram-bot:masterfrom
Enesuygurs:fix/mention-filter-user-without-username
Open

Enesuygurs wants to merge 1 commit into
python-telegram-bot:masterfrom
Enesuygurs:fix/mention-filter-user-without-username

Conversation

@Enesuygurs

Copy link
Copy Markdown

filters.Mention(user) compares user.username with the username of every text-mentioned user. When the given user has no username, that comparison is None == None. So the filter matches a text mention of any user without a username, even when the user ids differ:

alice = User(1, "Alice", False)  # no username
bob = User(2, "Bob", False)      # no username
msg = Message(1, now, Chat(1, "group"), text="Bob",
              entities=[MessageEntity(MessageEntity.TEXT_MENTION, 0, 3, user=bob)])
filters.Mention(alice).check_update(Update(1, message=msg))  # True, should be False

Telegram uses text mentions for users who don't have a username, so this is the common case for them. The existing tests didn't catch it because every text-mentioned user in them has a username.

With this change, usernames are only compared when the given user actually has one. Matching by id and by @username mention is unchanged.

Check-list for PRs

  • Created new or adapted existing unit tests
  • Checked the Stability Policy in case of deprecations or changes to documented behavior (bug fix only, no API change)

A `User` passed to `filters.Mention` that has no username matched every
text mention of another user without a username, because `None == None`
was treated as a username match. Only compare usernames if the given user
actually has one.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant