changeset: 77121:b4d257c64db7 parent: 77117:f4f2139202c5 parent: 77120:d769e64aed79 user: Senthil Kumaran date: Thu May 24 21:57:38 2012 +0800 files: Misc/NEWS description: Issue #14036: return None when port in urlparse cross 65535 diff -r f4f2139202c5 -r b4d257c64db7 Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Wed May 23 23:17:22 2012 +0200 +++ b/Lib/test/test_urlparse.py Thu May 24 21:57:38 2012 +0800 @@ -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 -r f4f2139202c5 -r b4d257c64db7 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Wed May 23 23:17:22 2012 +0200 +++ b/Lib/urllib/parse.py Thu May 24 21:57:38 2012 +0800 @@ -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 -r f4f2139202c5 -r b4d257c64db7 Misc/NEWS --- a/Misc/NEWS Wed May 23 23:17:22 2012 +0200 +++ b/Misc/NEWS Thu May 24 21:57:38 2012 +0800 @@ -42,6 +42,9 @@ Library ------- +- Issue #14036: Add an additional check to validate that port in urlparse does + not go in illegal range and returns None. + - Issue #14862: Add missing names to os.__all__ - Issue #14875: Use float('inf') instead of float('1e66666') in the json module.

AltStyle によって変換されたページ (->オリジナル) /