Skip to content

Commit 72d8357

Browse files
restore _clean_link method from collector.py to pass tests
1 parent e326ca3 commit 72d8357

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Diff for: tests/unit/test_collector.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,27 @@
2727
from pip._internal.index.sources import _FlatDirectorySource, _IndexDirectorySource
2828
from pip._internal.models.candidate import InstallationCandidate
2929
from pip._internal.models.index import PyPI
30-
from pip._internal.models.link import Link, _clean_link, _clean_url_path
30+
from pip._internal.models.link import Link, _clean_url_path
3131
from pip._internal.network.session import PipSession
3232
from tests.lib import TestData, make_test_link_collector
3333
from tests.lib.path import Path
3434

3535

36+
def _clean_link(url: str) -> str:
37+
"""
38+
Make sure a link is fully quoted.
39+
For example, if ' ' occurs in the URL, it will be replaced with "%20",
40+
and without double-quoting other characters.
41+
"""
42+
# Split the URL into parts according to the general structure
43+
# `scheme://netloc/path;parameters?query#fragment`.
44+
result = urllib.parse.urlparse(url)
45+
# If the netloc is empty, then the URL refers to a local filesystem path.
46+
is_local_path = not result.netloc
47+
path = _clean_url_path(result.path, is_local_path=is_local_path)
48+
return urllib.parse.urlunparse(result._replace(path=path))
49+
50+
3651
@pytest.mark.parametrize(
3752
"url",
3853
[
@@ -414,7 +429,7 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
414429
],
415430
)
416431
def test_clean_link(url: str, clean_url: str) -> None:
417-
assert _clean_link(Link(url)).parsed == urllib.parse.urlsplit(clean_url)
432+
assert _clean_link(url) == clean_url
418433

419434

420435
def _test_parse_links_data_attribute(

0 commit comments

Comments
 (0)