Skip to content
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

Closed
wants to merge 17 commits into from

Conversation

gorogoroumaru
Copy link

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.

@gorogoroumaru gorogoroumaru requested a review from asvetlov as a code owner April 14, 2020 06:39
@codecov-io
Copy link

codecov-io commented Apr 14, 2020

Codecov Report

Merging #4692 into master will decrease coverage by 0.01%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
aiohttp/web_urldispatcher.py 98.79% <33.33%> (-0.30%) ⬇️
aiohttp/web.py 99.05% <0.00%> (+<0.01%) ⬆️
aiohttp/client_reqrep.py 97.04% <0.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16a49c1...83f1ea2. Read the comment docs.

Comment on lines 981 to 983
raise ValueError('Incorrect route name {!r}, '
'python keywords cannot be used '
'for route name'.format(name))
Copy link
Member

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

Suggested change
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.

@@ -977,9 +977,13 @@ def register_resource(self, resource: AbstractResource) -> None:
name = resource.name

if name is not None:
if keyword.iskeyword(name):
Copy link
Member

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?

Suggested change
if keyword.iskeyword(name):
if keyword.iskeyword(name.strip()):

Copy link
Member

@webknjaz webknjaz left a 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.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Apr 15, 2020
@gorogoroumaru
Copy link
Author

Thanks!
I applied your suggested change.

@webknjaz
Copy link
Member

Great, waiting for the test, then!

@gorogoroumaru gorogoroumaru requested a review from webknjaz April 19, 2020 00:16
@gorogoroumaru
Copy link
Author

Test completed!

Copy link
Member

@webknjaz webknjaz left a 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.

Copy link
Member

@webknjaz webknjaz left a 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.


wrong_name = "for"
resource = PlainResource(url.raw_path, name=wrong_name)
with pytest.raises(ValueError):
Copy link
Member

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)

Comment on lines 422 to 426

wrong_name = "for"
resource = PlainResource(url.raw_path, name=wrong_name)
with pytest.raises(ValueError):
router.register_resource(resource)
Copy link
Member

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 🔥
Copy link
Member

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.

Copy link
Author

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.

@gorogoroumaru
Copy link
Author

I finished rebasing PR and applying suggested changes.

@asvetlov
Copy link
Member

Thanks for the PR.
I've ported your changes to a little bit more correct #5051

@asvetlov asvetlov closed this Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot have python keyword in route name
5 participants