|
7 | 7 |
|
8 | 8 | from pip._internal.download import PipSession
|
9 | 9 | from pip._internal.index import (
|
10 |
| - Link, PackageFinder, _determine_base_url, _egg_info_matches, |
| 10 | + Link, PackageFinder, _clean_link, _determine_base_url, _egg_info_matches, |
11 | 11 | _find_name_version_sep, _get_html_page,
|
12 | 12 | )
|
13 | 13 |
|
@@ -280,3 +280,65 @@ def test_request_retries(caplog):
|
280 | 280 | 'Could not fetch URL http://localhost: Retry error - skipping'
|
281 | 281 | in caplog.text
|
282 | 282 | )
|
| 283 | + |
| 284 | + |
| 285 | +@pytest.mark.parametrize( |
| 286 | + ("url", "clean_url"), |
| 287 | + [ |
| 288 | + # URL with hostname and port. Port separator should not be quoted. |
| 289 | + ("https://localhost.localdomain:8181/path/with space/", |
| 290 | + "https://localhost.localdomain:8181/path/with%20space/"), |
| 291 | + # URL that is already properly quoted. The quoting `%` |
| 292 | + # characters should not be quoted again. |
| 293 | + ("https://localhost.localdomain:8181/path/with%20quoted%20space/", |
| 294 | + "https://localhost.localdomain:8181/path/with%20quoted%20space/"), |
| 295 | + # URL with IPv4 address and port. |
| 296 | + ("https://127.0.0.1:8181/path/with space/", |
| 297 | + "https://127.0.0.1:8181/path/with%20space/"), |
| 298 | + # URL with IPv6 address and port. The `[]` brackets around the |
| 299 | + # IPv6 address should not be quoted. |
| 300 | + ("https://[fd00:0:0:236::100]:8181/path/with space/", |
| 301 | + "https://[fd00:0:0:236::100]:8181/path/with%20space/"), |
| 302 | + # URL with query. The leading `?` should not be quoted. |
| 303 | + ("https://localhost.localdomain:8181/path/with/query?request=test", |
| 304 | + "https://localhost.localdomain:8181/path/with/query?request=test"), |
| 305 | + # URL with colon in the path portion. |
| 306 | + ("https://localhost.localdomain:8181/path:/with:/colon", |
| 307 | + "https://localhost.localdomain:8181/path%3A/with%3A/colon"), |
| 308 | + # URL with something that looks like a drive letter, but is |
| 309 | + # not. The `:` should be quoted. |
| 310 | + ("https://localhost.localdomain/T:/path/", |
| 311 | + "https://localhost.localdomain/T%3A/path/") |
| 312 | + ] |
| 313 | +) |
| 314 | +def test_clean_link(url, clean_url): |
| 315 | + assert(_clean_link(url) == clean_url) |
| 316 | + |
| 317 | + |
| 318 | +@pytest.mark.parametrize( |
| 319 | + ("url", "clean_url"), |
| 320 | + [ |
| 321 | + # URL with Windows drive letter. The `:` after the drive |
| 322 | + # letter should not be quoted. The trailing `/` should be |
| 323 | + # removed. |
| 324 | + ("file:///T:/path/with spaces/", |
| 325 | + "file:///T:/path/with%20spaces") |
| 326 | + ] |
| 327 | +) |
| 328 | +@pytest.mark.skipif("sys.platform != 'win32'") |
| 329 | +def test_clean_link_windows(url, clean_url): |
| 330 | + assert(_clean_link(url) == clean_url) |
| 331 | + |
| 332 | + |
| 333 | +@pytest.mark.parametrize( |
| 334 | + ("url", "clean_url"), |
| 335 | + [ |
| 336 | + # URL with Windows drive letter, running on non-windows |
| 337 | + # platform. The `:` after the drive should be quoted. |
| 338 | + ("file:///T:/path/with spaces/", |
| 339 | + "file:///T%3A/path/with%20spaces/") |
| 340 | + ] |
| 341 | +) |
| 342 | +@pytest.mark.skipif("sys.platform == 'win32'") |
| 343 | +def test_clean_link_non_windows(url, clean_url): |
| 344 | + assert(_clean_link(url) == clean_url) |
0 commit comments