Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2fc5a50

Browse files
committed
Issue #14036: return None when port in urlparse cross 65535
1 parent 346c5de commit 2fc5a50

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ def test_urlsplit_attributes(self):
524524
self.assertEqual(p.port, 80)
525525
self.assertEqual(p.geturl(), url)
526526

527+
# Verify an illegal port is returned as None
528+
url = b"HTTP://WWW.PYTHON.ORG:65536/doc/#frag"
529+
p = urllib.parse.urlsplit(url)
530+
self.assertEqual(p.port, None)
531+
527532
def test_attributes_bad_port(self):
528533
"""Check handling of non-integer ports."""
529534
p = urllib.parse.urlsplit("http://www.example.net:foo")

Lib/urllib/parse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def port(self):
143143
port = self._hostinfo[1]
144144
if port is not None:
145145
port = int(port, 10)
146+
# Return None on an illegal port
147+
if not ( 0 <= port <= 65535):
148+
return None
146149
return port
147150

148151

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Core and Builtins
6767
Library
6868
-------
6969

70+
- Issue #14036: Add an additional check to validate that port in urlparse does
71+
not go in illegal range and returns None.
72+
7073
- Issue #14875: Use float('inf') instead of float('1e66666') in the json module.
7174

7275
- Issue #14426: Correct the Date format in Expires attribute of Set-Cookie

0 commit comments

Comments
 (0)