Skip to content

Commit

Permalink
[1.26] Strip leading zeros from ports
Browse files Browse the repository at this point in the history
Co-authored-by: Bastian Venthur <bastian.venthur@flixbus.com>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
  • Loading branch information
3 people committed Nov 22, 2022
1 parent b8c5d45 commit 955da4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/urllib3/util/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
BRACELESS_IPV6_ADDRZ_RE = re.compile("^" + IPV6_ADDRZ_PAT[2:-2] + "$")
ZONE_ID_RE = re.compile("(" + ZONE_ID_PAT + r")\]$")

_HOST_PORT_PAT = ("^(%s|%s|%s)(?::([0-9]{0,5}))?$") % (
_HOST_PORT_PAT = ("^(%s|%s|%s)(?::0*([0-9]{0,5}))?$") % (
REG_NAME_PAT,
IPV4_PAT,
IPV6_ADDRZ_PAT,
Expand Down
4 changes: 4 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ def test_parse_url_negative_port(self):
with pytest.raises(LocationParseError):
parse_url("https://www.google.com:-80/")

def test_parse_url_remove_leading_zeros(self):
url = parse_url("https://example.com:0000000000080")
assert url.port == 80

def test_Url_str(self):
U = Url("http", host="google.com")
assert str(U) == U.url
Expand Down

0 comments on commit 955da4d

Please sign in to comment.