Fix strip_url() removing default port from password. (#7605)

This commit is contained in:
Nishita Matlani 2026-06-15 02:41:55 -04:00 committed by GitHub
parent 3a36955261
commit f63a3aff25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -139,7 +139,8 @@ def strip_url(
("ftp", 21), ("ftp", 21),
} }
): ):
netloc = netloc.replace(f":{parsed_url.port}", "") port_suffix = f":{parsed_url.port}"
netloc = netloc.removesuffix(port_suffix)
return urlunparse( return urlunparse(
( (

View File

@ -346,6 +346,18 @@ class TestStripUrl:
"ftp://username:password@www.example.com:221/file.txt", "ftp://username:password@www.example.com:221/file.txt",
"ftp://username:password@www.example.com:221/file.txt", "ftp://username:password@www.example.com:221/file.txt",
), ),
(
"http://user:80@www.example.com:80/index.html",
"http://user:80@www.example.com/index.html",
),
(
"https://user:443@www.example.com:443/index.html",
"https://user:443@www.example.com/index.html",
),
(
"ftp://user:21@www.example.com:21/file.txt",
"ftp://user:21@www.example.com/file.txt",
),
], ],
) )
def test_default_ports(self, url: str, expected: str) -> None: def test_default_ports(self, url: str, expected: str) -> None: