summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastian Venthur <bastian.venthur@flixbus.com>2022-11-22 17:06:51 +0100
committerGitHub <noreply@github.com>2022-11-22 10:06:51 -0600
commit77fa67aaf2dc18962fa9234d47400c8a6fc1edf4 (patch)
tree3746384201b9c2a561ffe18e25bb8ccb1f18ac1b
parentfe39ebfb948db43002547b9258273182705b5434 (diff)
downloadurllib3-77fa67aaf2dc18962fa9234d47400c8a6fc1edf4.tar.gz
Strip leading zeros from ports
-rw-r--r--changelog/2804.bugfix.rst2
-rw-r--r--src/urllib3/util/url.py2
-rw-r--r--test/test_util.py4
3 files changed, 7 insertions, 1 deletions
diff --git a/changelog/2804.bugfix.rst b/changelog/2804.bugfix.rst
new file mode 100644
index 00000000..99273613
--- /dev/null
+++ b/changelog/2804.bugfix.rst
@@ -0,0 +1,2 @@
+Fixed issue in parse_url that rejected ASCII digits with more than 5 characters
+(i.e. lots of leading zeros but still <= 65535).
diff --git a/src/urllib3/util/url.py b/src/urllib3/util/url.py
index 272cc1c8..18f718f1 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-9]{0,5}))?$") % (
+_HOST_PORT_PAT = ("^(%s|%s|%s)(?::0*([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 e64c0cfc..78243552 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -348,6 +348,10 @@ class TestUtil:
with pytest.raises(LocationParseError):
parse_url("https://www.google.com:-80/")
+ def test_parse_url_remove_leading_zeros(self) -> None:
+ url = parse_url("https://example.com:0000000000080")
+ assert url.port == 80
+
def test_Url_str(self) -> None:
U = Url("http", host="google.com")
assert str(U) == U.url