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

Polish quoting #2668

Merged
merged 5 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/2668.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do percent encoding for `.url_for()` parameters
1 change: 1 addition & 0 deletions CHANGES/2668.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Forbid non-strings in `resource.url_for()` parameters.
6 changes: 3 additions & 3 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ def _match(self, path):
return None
else:
return {key: URL.build(path=value, encoded=True).path
for key, value in
match.groupdict().items()}
for key, value in match.groupdict().items()}

def raw_match(self, path):
return self._formatter == path
Expand All @@ -416,7 +415,8 @@ def get_info(self):
'pattern': self._pattern}

def url_for(self, **parts):
url = self._formatter.format_map(parts)
url = self._formatter.format_map({k: URL.build(path=v).raw_path
for k, v in parts.items()})
return URL.build(path=url)

def __repr__(self):
Expand Down
10 changes: 9 additions & 1 deletion tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,18 @@ def test_route_dynamic_with_regex(router):
handler = make_handler()
route = router.add_route('GET', r'/{one}/{two:.+}', handler)

url = route.url_for(one=1, two=2)
url = route.url_for(one='1', two='2')
assert '/1/2' == str(url)


def test_route_dynamic_quoting(router):
handler = make_handler()
route = router.add_route('GET', r'/{arg}', handler)

url = route.url_for(arg='1 2/текст')
assert '/1%202/%D1%82%D0%B5%D0%BA%D1%81%D1%82' == str(url)


async def test_regular_match_info(router):
handler = make_handler()
router.add_route('GET', '/get/{name}', handler)
Expand Down