diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2021-05-05 22:50:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-05 22:50:05 (GMT) |
commit | 985ac016373403e8ad41f8d563c4355ffa8d49ff (patch) | |
tree | c461373b90899ad9fe5e93b72f53ee8d84303f1f /Lib/test/test_urlparse.py | |
parent | 47895e31b6f626bc6ce47d175fe9d43c1098909d (diff) | |
download | cpython-985ac016373403e8ad41f8d563c4355ffa8d49ff.zip cpython-985ac016373403e8ad41f8d563c4355ffa8d49ff.tar.gz cpython-985ac016373403e8ad41f8d563c4355ffa8d49ff.tar.bz2 |
bpo-43882 Remove the newline, and tab early. From query and fragments. (GH-25921)
Diffstat (limited to 'Lib/test/test_urlparse.py')
-rw-r--r-- | Lib/test/test_urlparse.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 67341fe..31943f3 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -614,32 +614,40 @@ class UrlParseTestCase(unittest.TestCase): def test_urlsplit_remove_unsafe_bytes(self): # Remove ASCII tabs and newlines from input - url = "http://www.python.org/java\nscript:\talert('msg\r\n')/#frag" + url = "http\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, "http") self.assertEqual(p.netloc, "www.python.org") self.assertEqual(p.path, "/javascript:alert('msg')/") - self.assertEqual(p.query, "") - self.assertEqual(p.fragment, "frag") + self.assertEqual(p.query, "query=something") + self.assertEqual(p.fragment, "fragment") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, "www.python.org") self.assertEqual(p.port, None) - self.assertEqual(p.geturl(), "http://www.python.org/javascript:alert('msg')/#frag") + self.assertEqual(p.geturl(), "http://www.python.org/javascript:alert('msg')/?query=something#fragment") # Remove ASCII tabs and newlines from input as bytes. - url = b"http://www.python.org/java\nscript:\talert('msg\r\n')/#frag" + url = b"http\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, b"http") self.assertEqual(p.netloc, b"www.python.org") self.assertEqual(p.path, b"/javascript:alert('msg')/") - self.assertEqual(p.query, b"") - self.assertEqual(p.fragment, b"frag") + self.assertEqual(p.query, b"query=something") + self.assertEqual(p.fragment, b"fragment") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, b"www.python.org") self.assertEqual(p.port, None) - self.assertEqual(p.geturl(), b"http://www.python.org/javascript:alert('msg')/#frag") + self.assertEqual(p.geturl(), b"http://www.python.org/javascript:alert('msg')/?query=something#fragment") + + # with scheme as cache-key + url = "http://www.python.org/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" + scheme = "ht\ntp" + for _ in range(2): + p = urllib.parse.urlsplit(url, scheme=scheme) + self.assertEqual(p.scheme, "http") + self.assertEqual(p.geturl(), "http://www.python.org/javascript:alert('msg')/?query=something#fragment") def test_attributes_bad_port(self): """Check handling of invalid ports.""" |