Skip to content

Commit be89ea5

Browse files
committed
Correctly handle file://localhost/ and file:///
According to RFC 8089, an empty host value (i.e. "file:///") should be taken to be "localhost" (i.e. "file://localhost/"), so we need to perform some additional normalization to compare such URLs correctly.
1 parent 6db4003 commit be89ea5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

news/10162.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
New resolver: URL comparison logic now treats ``file://localhost/`` and
2+
``file:///`` as equivalent to conform to RFC 8089.

src/pip/_internal/models/link.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class _CleanResult(NamedTuple):
260260
def from_link(cls, link: Link) -> "_CleanResult":
261261
parsed = link._parsed_url
262262
netloc = parsed.netloc.rsplit("@", 1)[-1]
263+
# According to RFC 8089, an empty host in file: means localhost.
264+
if parsed.scheme == "file" and not netloc:
265+
netloc = "localhost"
263266
fragment = urllib.parse.parse_qs(parsed.fragment)
264267
if "egg" in fragment:
265268
logger.debug("Ignoring egg= fragment in %s", link)

0 commit comments

Comments
 (0)