Skip to content

Commit 2e21934

Browse files
authored
Fix cleaning of local URLs with VCS schemes (#13509)
Ensure that the scheme is `"file"` when we call `urlunsplit()`. This ensures that a URL with an explicit authority section is returned.
1 parent 853a593 commit 2e21934

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

news/13509.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix normalization of local links with non-``file`` schemes.

src/pip/_internal/models/link.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ def _ensure_quoted_url(url: str) -> str:
177177
# If the netloc is empty, then the URL refers to a local filesystem path.
178178
is_local_path = not result.netloc
179179
path = _clean_url_path(result.path, is_local_path=is_local_path)
180-
return urllib.parse.urlunsplit(result._replace(path=path))
180+
# Temporarily replace scheme with file to ensure the URL generated by
181+
# urlunsplit() contains an empty netloc (file://) as per RFC 1738.
182+
ret = urllib.parse.urlunsplit(result._replace(scheme="file", path=path))
183+
ret = result.scheme + ret[4:] # Restore original scheme.
184+
return ret
181185

182186

183187
def _absolute_link_url(base_url: str, url: str) -> str:

tests/unit/test_collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
436436
# running on non-windows platform.
437437
pytest.param(
438438
"git+file:///T:/with space/[email protected]#egg=my-package-1.0",
439-
"git+file:/T%3A/with%20space/[email protected]#egg=my-package-1.0",
439+
"git+file:///T%3A/with%20space/[email protected]#egg=my-package-1.0",
440440
marks=pytest.mark.skipif("sys.platform == 'win32'"),
441441
),
442442
],

0 commit comments

Comments
 (0)