Skip to content

Commit 265b4e7

Browse files
committed
Protect @ as safe character when cleaning URLs
Remote URLs that contain a link to a git repository and a tag reference will have the `@` character converted into `%40`. This is incorrect. Fixes: pypa#6437 Signed-off-by: Nicolas Bock <[email protected]>
1 parent 9816d17 commit 265b4e7

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

news/6440.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a regression that caused `@` to be quoted in pypiserver links.
2+
This interfered with parsing the revision string from VCS urls.

src/pip/_internal/index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ class FoundCandidates(object):
336336
* `evaluator`: A CandidateEvaluator object to sort applicable candidates
337337
by order of preference.
338338
"""
339+
339340
def __init__(
340341
self,
341342
candidates, # type: List[InstallationCandidate]
@@ -1061,7 +1062,9 @@ def _clean_link(url):
10611062
path = urllib_request.pathname2url(
10621063
urllib_request.url2pathname(result.path))
10631064
else:
1064-
path = urllib_parse.quote(urllib_parse.unquote(result.path))
1065+
# In addition to the `/` character we protect `@` so that
1066+
# revision strings in VCS URLs are properly parsed.
1067+
path = urllib_parse.quote(urllib_parse.unquote(result.path), safe="/@")
10651068
return urllib_parse.urlunparse(result._replace(path=path))
10661069

10671070

tests/unit/test_index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ def test_request_retries(caplog):
308308
# URL with something that looks like a drive letter, but is
309309
# not. The `:` should be quoted.
310310
("https://localhost.localdomain/T:/path/",
311-
"https://localhost.localdomain/T%3A/path/")
311+
"https://localhost.localdomain/T%3A/path/"),
312+
# VCS URL containing revision string.
313+
("git+ssh://example.com/path to/[email protected]#egg=my-package-1.0",
314+
"git+ssh://example.com/path%20to/[email protected]#egg=my-package-1.0")
312315
]
313316
)
314317
def test_clean_link(url, clean_url):

0 commit comments

Comments
 (0)