Skip to content

Commit 07ccc26

Browse files
CPython developersyouknowone
authored andcommitted
Update test_urlparse from CPython 3.10.5
1 parent 27d1c34 commit 07ccc26

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

Lib/test/test_urlparse.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ def test_urlsplit_attributes(self):
613613
p.port
614614

615615
def test_urlsplit_remove_unsafe_bytes(self):
616-
# Remove ASCII tabs and newlines from input, for http common case scenario.
617-
url = "h\nttp://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
616+
# Remove ASCII tabs and newlines from input
617+
url = "http\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
618618
p = urllib.parse.urlsplit(url)
619619
self.assertEqual(p.scheme, "http")
620620
self.assertEqual(p.netloc, "www.python.org")
@@ -627,8 +627,8 @@ def test_urlsplit_remove_unsafe_bytes(self):
627627
self.assertEqual(p.port, None)
628628
self.assertEqual(p.geturl(), "http://www.python.org/javascript:alert('msg')/?query=something#fragment")
629629

630-
# Remove ASCII tabs and newlines from input as bytes, for http common case scenario.
631-
url = b"h\nttp://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
630+
# Remove ASCII tabs and newlines from input as bytes.
631+
url = b"http\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
632632
p = urllib.parse.urlsplit(url)
633633
self.assertEqual(p.scheme, b"http")
634634
self.assertEqual(p.netloc, b"www.python.org")
@@ -641,24 +641,13 @@ def test_urlsplit_remove_unsafe_bytes(self):
641641
self.assertEqual(p.port, None)
642642
self.assertEqual(p.geturl(), b"http://www.python.org/javascript:alert('msg')/?query=something#fragment")
643643

644-
# any scheme
645-
url = "x-new-scheme\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
646-
p = urllib.parse.urlsplit(url)
647-
self.assertEqual(p.geturl(), "x-new-scheme://www.python.org/javascript:alert('msg')/?query=something#fragment")
648-
649-
# Remove ASCII tabs and newlines from input as bytes, any scheme.
650-
url = b"x-new-scheme\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
651-
p = urllib.parse.urlsplit(url)
652-
self.assertEqual(p.geturl(), b"x-new-scheme://www.python.org/javascript:alert('msg')/?query=something#fragment")
653-
654-
# Unsafe bytes is not returned from urlparse cache.
655-
# scheme is stored after parsing, sending an scheme with unsafe bytes *will not* return an unsafe scheme
656-
url = "https://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
657-
scheme = "htt\nps"
644+
# with scheme as cache-key
645+
url = "http://www.python.org/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment"
646+
scheme = "ht\ntp"
658647
for _ in range(2):
659648
p = urllib.parse.urlsplit(url, scheme=scheme)
660-
self.assertEqual(p.scheme, "https")
661-
self.assertEqual(p.geturl(), "https://www.python.org/javascript:alert('msg')/?query=something#fragment")
649+
self.assertEqual(p.scheme, "http")
650+
self.assertEqual(p.geturl(), "http://www.python.org/javascript:alert('msg')/?query=something#fragment")
662651

663652
def test_attributes_bad_port(self):
664653
"""Check handling of invalid ports."""
@@ -745,15 +734,17 @@ def test_withoutscheme(self):
745734

746735
def test_portseparator(self):
747736
# Issue 754016 makes changes for port separator ':' from scheme separator
748-
self.assertEqual(urllib.parse.urlparse("path:80"),
749-
('','','path:80','','',''))
737+
self.assertEqual(urllib.parse.urlparse("http:80"), ('http','','80','','',''))
738+
self.assertEqual(urllib.parse.urlparse("https:80"), ('https','','80','','',''))
739+
self.assertEqual(urllib.parse.urlparse("path:80"), ('path','','80','','',''))
750740
self.assertEqual(urllib.parse.urlparse("http:"),('http','','','','',''))
751741
self.assertEqual(urllib.parse.urlparse("https:"),('https','','','','',''))
752742
self.assertEqual(urllib.parse.urlparse("http://www.python.org:80"),
753743
('http','www.python.org:80','','','',''))
754744
# As usual, need to check bytes input as well
755-
self.assertEqual(urllib.parse.urlparse(b"path:80"),
756-
(b'',b'',b'path:80',b'',b'',b''))
745+
self.assertEqual(urllib.parse.urlparse(b"http:80"), (b'http',b'',b'80',b'',b'',b''))
746+
self.assertEqual(urllib.parse.urlparse(b"https:80"), (b'https',b'',b'80',b'',b'',b''))
747+
self.assertEqual(urllib.parse.urlparse(b"path:80"), (b'path',b'',b'80',b'',b'',b''))
757748
self.assertEqual(urllib.parse.urlparse(b"http:"),(b'http',b'',b'',b'',b'',b''))
758749
self.assertEqual(urllib.parse.urlparse(b"https:"),(b'https',b'',b'',b'',b'',b''))
759750
self.assertEqual(urllib.parse.urlparse(b"http://www.python.org:80"),

0 commit comments

Comments
 (0)