summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-05-24 13:56:17 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-05-24 13:56:17 (GMT)
commit2fc5a5080923f243a78b13cca0fd09f8db26eff6 (patch)
tree19f2eff518b2d2018aa0add9292cc39e2a5d60cc /Lib
parent346c5de08e92001f0b26b4d07d8f2a22a21d2f1e (diff)
downloadcpython-2fc5a5080923f243a78b13cca0fd09f8db26eff6.zip
cpython-2fc5a5080923f243a78b13cca0fd09f8db26eff6.tar.gz
cpython-2fc5a5080923f243a78b13cca0fd09f8db26eff6.tar.bz2
Issue #14036: return None when port in urlparse cross 65535
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/test/test_urlparse.py5
-rw-r--r--Lib/urllib/parse.py3
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 73150cf..e9adaef 100755
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -524,6 +524,11 @@ class UrlParseTestCase(unittest.TestCase):
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
index 92170ad..528c0a7 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -143,6 +143,9 @@ class _NetlocResultMixinBase(object):
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