Skip to content

Commit 955da4d

Browse files
sethmlarsonventhurhramezani
authored
[1.26] Strip leading zeros from ports
Co-authored-by: Bastian Venthur <bastian.venthur@flixbus.com> Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
1 parent b8c5d45 commit 955da4d

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/urllib3/util/url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
BRACELESS_IPV6_ADDRZ_RE = re.compile("^" + IPV6_ADDRZ_PAT[2:-2] + "$")
6464
ZONE_ID_RE = re.compile("(" + ZONE_ID_PAT + r")\]$")
6565

66-
_HOST_PORT_PAT = ("^(%s|%s|%s)(?::([0-9]{0,5}))?$") % (
66+
_HOST_PORT_PAT = ("^(%s|%s|%s)(?::0*([0-9]{0,5}))?$") % (
6767
REG_NAME_PAT,
6868
IPV4_PAT,
6969
IPV6_ADDRZ_PAT,

test/test_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ def test_parse_url_negative_port(self):
347347
with pytest.raises(LocationParseError):
348348
parse_url("https://www.google.com:-80/")
349349

350+
def test_parse_url_remove_leading_zeros(self):
351+
url = parse_url("https://example.com:0000000000080")
352+
assert url.port == 80
353+
350354
def test_Url_str(self):
351355
U = Url("http", host="google.com")
352356
assert str(U) == U.url

0 commit comments

Comments
 (0)