python-urllib3/backport-fixed-issue-with-port-0-returning-None.patch
chenhaxing e7f6a150fa backport some patches
(cherry picked from commit 88a2557b1a5aa68af23ccd5dc2c7b93355a43179)
2023-01-18 14:44:35 +08:00

47 lines
1.6 KiB
Diff

From 7b6049c4d7551c0a3d04e213b853ef33b8ed1cd9 Mon Sep 17 00:00:00 2001
From: Bastian Venthur <venthur@debian.org>
Date: Fri, 9 Dec 2022 21:47:14 +0100
Subject: [PATCH] fixed issue with port "0" returning None
Conflict:adapt:
1.no change changelog/2850.bugfix.rst
2.The content of "@@" is adapted
Reference:https://github.com/urllib3/urllib3/pull/2849
---
src/urllib3/util/url.py | 2 +-
test/test_util.py | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/urllib3/util/url.py b/src/urllib3/util/url.py
index 6793de3..701ad75 100644
--- a/src/urllib3/util/url.py
+++ b/src/urllib3/util/url.py
@@ -63,7 +63,7 @@ IPV6_ADDRZ_RE = re.compile("^" + IPV6_ADDRZ_PAT + "$")
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*([0-9]{0,5}))?$") % (
+_HOST_PORT_PAT = ("^(%s|%s|%s)(?::0*?(|0|[1-9][0-9]{0,5}))?$") % (
REG_NAME_PAT,
IPV4_PAT,
IPV6_ADDRZ_PAT,
diff --git a/test/test_util.py b/test/test_util.py
index 165a331..c8729e8 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -343,6 +343,13 @@ class TestUtil(object):
url = parse_url("https://example.com:0000000000080")
assert url.port == 80
+ def test_parse_url_only_zeros(self) -> None:
+ url = parse_url("https://example.com:0")
+ assert url.port == 0
+
+ url = parse_url("https://example.com:000000000000")
+ assert url.port == 0
+
def test_Url_str(self):
U = Url("http", host="google.com")
assert str(U) == U.url
--
2.27.0