Commit cdbb70e7 by Jan Luca Naumann Committed by GitHub

Fix format string for url cleaning of other sources (#5392)

This commit added also a test for the cleaning function to catch
regressions in the future.
parent a84df8da
......@@ -144,7 +144,7 @@ class Page:
"""Makes sure a link is fully encoded. That is, if a ' ' shows up in
the link, it will be rewritten to %20 (while not over-quoting
% or other characters)."""
return self._clean_re.sub(lambda match: f"%{match.group(0):2x}", url)
return self._clean_re.sub(lambda match: f"%{ord(match.group(0)):02x}", url)
# TODO: revisit whether the LegacyRepository should inherit from PyPiRepository.
......
......@@ -73,6 +73,15 @@ def test_page_absolute_links_path_are_correct():
assert link.path.startswith("/packages/")
def test_page_clean_link():
repo = MockRepository()
page = repo._get_page("/relative")
cleaned = page.clean_link('https://legacy.foo.bar/test /the"/cleaning\0')
assert cleaned == "https://legacy.foo.bar/test%20/the%22/cleaning%00"
def test_sdist_format_support():
repo = MockRepository()
page = repo._get_page("/relative")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment