[Python-checkins] cpython (3.2): Issue #14036: return None when port in urlparse cross 65535
senthil.kumaran
python-checkins at python.org
Thu May 24 15:57:55 CEST 2012
http://hg.python.org/cpython/rev/d769e64aed79
changeset: 77120:d769e64aed79
branch: 3.2
parent: 77114:de5cb14e929e
user: Senthil Kumaran <senthil at uthcode.com>
date: Thu May 24 21:56:17 2012 +0800
summary:
Issue #14036: return None when port in urlparse cross 65535
files:
Lib/test/test_urlparse.py | 5 +++++
Lib/urllib/parse.py | 3 +++
Misc/NEWS | 3 +++
3 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -524,6 +524,11 @@
self.assertEqual(p.port, 80)
self.assertEqual(p.geturl(), url)
+ # Verify an illegal port is returned as None
+ url = b"HTTP://WWW.PYTHON.ORG:65536/doc/#frag"
+ p = urllib.parse.urlsplit(url)
+ self.assertEqual(p.port, None)
+
def test_attributes_bad_port(self):
"""Check handling of non-integer ports."""
p = urllib.parse.urlsplit("http://www.example.net:foo")
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -143,6 +143,9 @@
port = self._hostinfo[1]
if port is not None:
port = int(port, 10)
+ # Return None on an illegal port
+ if not ( 0 <= port <= 65535):
+ return None
return port
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,9 @@
Library
-------
+- Issue #14036: Add an additional check to validate that port in urlparse does
+ not go in illegal range and returns None.
+
- Issue #14875: Use float('inf') instead of float('1e66666') in the json module.
- Issue #14426: Correct the Date format in Expires attribute of Set-Cookie
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list