mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
gh-96035: Make urllib.parse.urlparse reject non-numeric ports (#98273)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
4ec9ed8fde
commit
6f15ca8c7a
3 changed files with 18 additions and 12 deletions
|
@ -653,13 +653,16 @@ class UrlParseTestCase(unittest.TestCase):
|
|||
"""Check handling of invalid ports."""
|
||||
for bytes in (False, True):
|
||||
for parse in (urllib.parse.urlsplit, urllib.parse.urlparse):
|
||||
for port in ("foo", "1.5", "-1", "0x10"):
|
||||
for port in ("foo", "1.5", "-1", "0x10", "-0", "1_1", " 1", "1 ", "६"):
|
||||
with self.subTest(bytes=bytes, parse=parse, port=port):
|
||||
netloc = "www.example.net:" + port
|
||||
url = "http://" + netloc
|
||||
if bytes:
|
||||
netloc = netloc.encode("ascii")
|
||||
url = url.encode("ascii")
|
||||
if netloc.isascii() and port.isascii():
|
||||
netloc = netloc.encode("ascii")
|
||||
url = url.encode("ascii")
|
||||
else:
|
||||
continue
|
||||
p = parse(url)
|
||||
self.assertEqual(p.netloc, netloc)
|
||||
with self.assertRaises(ValueError):
|
||||
|
@ -1199,6 +1202,7 @@ class Utility_Tests(unittest.TestCase):
|
|||
self.assertEqual(splitnport('127.0.0.1', 55), ('127.0.0.1', 55))
|
||||
self.assertEqual(splitnport('parrot:cheese'), ('parrot', None))
|
||||
self.assertEqual(splitnport('parrot:cheese', 55), ('parrot', None))
|
||||
self.assertEqual(splitnport('parrot: +1_0 '), ('parrot', None))
|
||||
|
||||
def test_splitquery(self):
|
||||
# Normal cases are exercised by other tests; ensure that we also
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue