1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

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.
This commit is contained in:
Tzu-ping Chung 2021-07-23 16:10:25 +08:00
parent 6db400328b
commit be89ea5d5b
2 changed files with 5 additions and 0 deletions

2
news/10162.bugfix.rst Normal file
View file

@ -0,0 +1,2 @@
New resolver: URL comparison logic now treats ``file://localhost/`` and
``file:///`` as equivalent to conform to RFC 8089.

View file

@ -260,6 +260,9 @@ class _CleanResult(NamedTuple):
def from_link(cls, link: Link) -> "_CleanResult":
parsed = link._parsed_url
netloc = parsed.netloc.rsplit("@", 1)[-1]
# According to RFC 8089, an empty host in file: means localhost.
if parsed.scheme == "file" and not netloc:
netloc = "localhost"
fragment = urllib.parse.parse_qs(parsed.fragment)
if "egg" in fragment:
logger.debug("Ignoring egg= fragment in %s", link)