bpo-30713: Reject newline in urllib.parse by vstinner · Pull Request #2301 · python/cpython (original) (raw)
@@ -981,6 +981,15 @@ def test_splittype(self):
self.assertEqual(splittype('type:'), ('type', ''))
self.assertEqual(splittype('type:opaque:string'), ('type', 'opaque:string'))
# bpo-30713: The newline character U+000A is invalid in URLs
for url in (
'\ntype:string',
'ty\npe:string',
'type:str\ning',
'type:string\n',
):
self.assertEqual(splittype(url), (None, url))
def test_splithost(self):
splithost = urllib.parse.splithost
self.assertEqual(splithost('//www.example.org:80/foo/bar/baz.html'),
@@ -1010,6 +1019,15 @@ def test_splithost(self):
self.assertEqual(splithost("//example.net/file#"),
('example.net', '/file#'))
# bpo-30713: The newline character U+000A is invalid in URLs
for url in (
'\n//hostname/url',
'//host\nname/url',
'//hostname/u\nrl',
'//hostname/url\n',
):
self.assertEqual(splithost(url), (None, url))
def test_splituser(self):
splituser = urllib.parse.splituser
self.assertEqual(splituser('User:Pass@www.python.org:080'),
@@ -1052,6 +1070,15 @@ def test_splitport(self):
self.assertEqual(splitport('[::1]'), ('[::1]', None))
self.assertEqual(splitport(':88'), ('', '88'))
# bpo-30713: The newline character U+000A is invalid in URLs
for url in (
'\nparrot:88',
'par\nrot:88',
'parrot:8\n8',
'parrot:88\n',
):
self.assertEqual(splitport(url), (url, None))
def test_splitnport(self):
splitnport = urllib.parse.splitnport
self.assertEqual(splitnport('parrot:88'), ('parrot', 88))