From d7bf668780e330cfcbf4cd082a5f41764f9bcaff Mon Sep 17 00:00:00 2001 From: chenhaxing Date: Fri, 10 Feb 2023 16:30:10 +0800 Subject: [PATCH] change _HOST_PORT_PAT to fix port is 0 but return None (cherry picked from commit 86df758dd5ab7eec6e6e96b0e9b53d2e458206fe) --- ...xed-issue-with-port-0-returning-None.patch | 48 +++++++++++++++++++ python-urllib3.spec | 9 +++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 backport-fixed-issue-with-port-0-returning-None.patch diff --git a/backport-fixed-issue-with-port-0-returning-None.patch b/backport-fixed-issue-with-port-0-returning-None.patch new file mode 100644 index 0000000..d96eab9 --- /dev/null +++ b/backport-fixed-issue-with-port-0-returning-None.patch @@ -0,0 +1,48 @@ +From 25fbd5fb72ae8790cff9512878d302120e387e64 Mon Sep 17 00:00:00 2001 +From: Anil Khatri +Date: Sat, 31 Dec 2022 01:38:50 +0530 +Subject: [PATCH] Fixed issue with port "0" returning None + +Conflict:adapt: +1.The content of "@@" is adapted +2.The line number is adapted +Reference:https://github.com/urllib3/urllib3/pull/2864 + +--- + 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 8964cef..63166e8 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,4}))?$") % ( + REG_NAME_PAT, + IPV4_PAT, + IPV6_ADDRZ_PAT, +diff --git a/test/test_util.py b/test/test_util.py +index f6c8b43..7d512f5 100644 +--- a/test/test_util.py ++++ b/test/test_util.py +@@ -347,6 +347,13 @@ class TestUtil(object): + url = parse_url("https://example.com:0000000000080") + assert url.port == 80 + ++ def test_parse_url_only_zeros(self): ++ 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 diff --git a/python-urllib3.spec b/python-urllib3.spec index cba28ae..be7fca4 100644 --- a/python-urllib3.spec +++ b/python-urllib3.spec @@ -3,7 +3,7 @@ Name: python-%{srcname} Version: 1.26.12 -Release: 2 +Release: 3 Summary: Sanity-friendly HTTP client for Python License: MIT URL: https://urllib3.readthedocs.io @@ -13,6 +13,7 @@ Source1: ssl_match_hostname_py3.py Patch0001: remove_mock.patch Patch6000: backport-CVE-2021-28363.patch Patch6001: backport-strip-leading-zeros-form-ports.patch +Patch6002: backport-fixed-issue-with-port-0-returning-None.patch BuildArch: noarch @@ -78,6 +79,12 @@ PYTHONPATH=%{buildroot}%{python3_sitelib}:%{python3_sitelib} %{__python3} -m pyt %{python3_sitelib}/urllib3-*.egg-info %changelog +* Fri Feb 10 2023 chenhaixing - 1.26.12-3 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:change _HOST_PORT_PAT to fix port is 0 but return None + * Sat Dec 17 2022 chenhaixing - 1.26.12-2 - DESC:fix util.parse_url function traceback when port have leading zeros -- Gitee