-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Fix bug in route name validation (#4691) #4692
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4692 +/- ##
==========================================
- Coverage 97.60% 97.58% -0.02%
==========================================
Files 43 43
Lines 8920 8931 +11
Branches 1406 1407 +1
==========================================
+ Hits 8706 8715 +9
- Misses 95 96 +1
- Partials 119 120 +1
Continue to review full report at Codecov.
|
aiohttp/web_urldispatcher.py
Outdated
raise ValueError('Incorrect route name {!r}, ' | ||
'python keywords cannot be used ' | ||
'for route name'.format(name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this could be an f-string
raise ValueError('Incorrect route name {!r}, ' | |
'python keywords cannot be used ' | |
'for route name'.format(name)) | |
raise ValueError(f'Incorrect route name {name!r}, ' | |
'python keywords cannot be used ' | |
'for route name') |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
aiohttp/web_urldispatcher.py
Outdated
@@ -977,9 +977,13 @@ def register_resource(self, resource: AbstractResource) -> None: | |||
name = resource.name | |||
|
|||
if name is not None: | |||
if keyword.iskeyword(name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we trim whitespaces first?
if keyword.iskeyword(name): | |
if keyword.iskeyword(name.strip()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @gorogoroumaru, Thanks for the PR!
This looks reasonable but to be accepted we need a regression test and a change fragment to be included in the PR. Also, please complete the PR template https://github.com/aio-libs/aiohttp/blob/master/.github/PULL_REQUEST_TEMPLATE.md.
Thanks! |
Great, waiting for the test, then! |
Test completed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currrently this PR contains unrelated changes, please rebase it on top of origin/master
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR needs rebasing so that unrelated changes made by someone else don't show up here.
tests/test_web_urldispatcher.py
Outdated
|
||
wrong_name = "for" | ||
resource = PlainResource(url.raw_path, name=wrong_name) | ||
with pytest.raises(ValueError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to use match=
arg as show @ #4692 (comment)
tests/test_web_urldispatcher.py
Outdated
|
||
wrong_name = "for" | ||
resource = PlainResource(url.raw_path, name=wrong_name) | ||
with pytest.raises(ValueError): | ||
router.register_resource(resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is a separate test and so it must be in a separate test function.
@@ -1,29 +1,12 @@ | |||
# Ref: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser | |||
blank_issues_enabled: false # default: true | |||
contact_links: | |||
- name: 🔐 Security bug report 🔥 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things like this mustn't be a part of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I wrongly operated git command and included someone else's commit to my PR.
# Conflicts: # tests/test_web_urldispatcher.py
I finished rebasing PR and applying suggested changes. |
Thanks for the PR. |
fix #4691
The register_resource function in aiohttp/web_urldispatcher.py had a bug in route name validation.
It validated each part of the splitted route name whether it's a python keyword.
I fixed the function to validate route name before splitting it and added a new error message.