8000 Fixed issue with port "0" returning None · urllib3/urllib3@25fbd5f · GitHub
[go: up one dir, main page]

Skip to content

Commit 25fbd5f

Browse files
authored
Fixed issue with port "0" returning None
1 parent 61e86ea commit 25fbd5f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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*([0-9]{0,5}))?$") % (
66+
_HOST_PORT_PAT = ("^(%s|%s|%s)(?::0*?(|0|[1-9][0-9]{0,4}))?$") % (
6767
REG_NAME_PAT,
6868
IPV4_PAT,
6969
IPV6_ADDRZ_PAT,

test/test_util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ def test_parse_url_remove_leading_zeros(self):
351351
url = parse_url("https://example.com:0000000000080")
352352
assert url.port == 80
353353

354+
def test_parse_url_only_zeros(self):
355+
url = parse_url("https://example.com:0")
356+
assert url.port == 0
357+
358+
url = parse_url("https://example.com:000000000000")
359+
assert url.port == 0
360+
354361
def test_Url_str(self):
355362
U = Url("http", host="google.com")
356363
assert str(U) == U.url

0 commit comments

Comments
 (0)
0