Skip to content

Fix BAD_PATTERN regex in deeplinking process.#1630

Merged
JrooTJunior merged 3 commits intoaiogram:dev-3.xfrom
amirsoroush:dev-3.x
Jan 16, 2025
Merged

Fix BAD_PATTERN regex in deeplinking process.#1630
JrooTJunior merged 3 commits intoaiogram:dev-3.xfrom
amirsoroush:dev-3.x

Conversation

@amirsoroush
Copy link
Contributor

Description

The regex pattern which identifies the "bad characters" for deeplink payload is not correct:

import re

print(f"{ord('A')=}")
print(f"{ord('Z')=}")
print(f"{ord('a')=}")
print(f"{ord('z')=}")
print("-----------------------------------")
for i in range(91, 97):
    print(f"{i}: {chr(i)}")
print("-----------------------------------")
print(re.search(r"[^A-z0-9-]", "hi`bye"))      # None
print(re.search(r"[^A-Za-z0-9-_]", "hi`bye"))  # <re.Match object; span=(2, 3), match='`'>

There is a gap between Z and a. We should explicitly include the ranges A-Z and a-z to avoid accepting characters like backtick.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I modified the WRONG_PAYLOADS list in tests/test_utils/test_deep_linking.py to demonstrate the bug.

Test Configuration:

  • Operating System: MacOS
  • Python version: 3.12

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Jan 14, 2025
@github-actions
Copy link

github-actions bot commented Jan 14, 2025

✔️ Changelog found.

Thank you for adding a description of the changes

Copy link
Contributor

@Olegt0rr Olegt0rr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

LGTM

@Olegt0rr Olegt0rr added the bug Something is wrong with the framework label Jan 15, 2025
@JrooTJunior JrooTJunior merged commit bbdc43b into aiogram:dev-3.x Jan 16, 2025
23 checks passed
@codecov
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (44bd8fe) to head (2a8328d).
Report is 3 commits behind head on dev-3.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1630   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          484       484           
  Lines        12205     12205           
=========================================
  Hits         12205     12205           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
aiogram/utils/deep_linking.py 100.00% <100.00%> (ø)

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

Labels

3.x Issue or PR for stable 3.x version bug Something is wrong with the framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants