Scrapy, a fast high-level web crawling & scraping framework for Python.
Fix strip_url() removing default port from password. (#7605)
Nishita Matlanif63a3aff254f
diff --git a/scrapy/utils/url.py b/scrapy/utils/url.pyindex 8f75e2618..4d2bbdda2 100644--- a/scrapy/utils/url.py+++ b/scrapy/utils/url.py@@ -139,7 +139,8 @@ def strip_url(("ftp", 21),}):- netloc = netloc.replace(f":{parsed_url.port}", "")+ port_suffix = f":{parsed_url.port}"+ netloc = netloc.removesuffix(port_suffix)return urlunparse((diff --git a/tests/test_utils_url.py b/tests/test_utils_url.pyindex 19a31c353..a74b9a41d 100644--- a/tests/test_utils_url.py+++ b/tests/test_utils_url.py@@ -346,6 +346,18 @@ class TestStripUrl:"ftp://username:[email protected]:221/file.txt","ftp://username:[email protected]:221/file.txt",),+ (+ "http://user:[email protected]:80/index.html",+ "http://user:[email protected]/index.html",+ ),+ (+ "https://user:[email protected]:443/index.html",+ "https://user:[email protected]/index.html",+ ),+ (+ "ftp://user:[email protected]:21/file.txt",+ "ftp://user:[email protected]/file.txt",+ ),],)def test_default_ports(self, url: str, expected: str) -> None: