Skip to content
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 news/13509.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix normalization of local links with non-``file`` schemes.
6 changes: 5 additions & 1 deletion src/pip/_internal/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def _ensure_quoted_url(url: str) -> str:
# If the netloc is empty, then the URL refers to a local filesystem path.
is_local_path = not result.netloc
path = _clean_url_path(result.path, is_local_path=is_local_path)
return urllib.parse.urlunsplit(result._replace(path=path))
# Temporarily replace scheme with file to ensure the URL generated by
# urlunsplit() contains an empty netloc (file://) as per RFC 1738.
ret = urllib.parse.urlunsplit(result._replace(scheme="file", path=path))
ret = result.scheme + ret[4:] # Restore original scheme.
return ret


def _absolute_link_url(base_url: str, url: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
# running on non-windows platform.
pytest.param(
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
"git+file:/T%3A/with%20space/repo.git@1.0#egg=my-package-1.0",
"git+file:///T%3A/with%20space/repo.git@1.0#egg=my-package-1.0",
marks=pytest.mark.skipif("sys.platform == 'win32'"),
),
],
Expand Down
Loading