[Python-checkins] bpo-38449: Add URL delimiters test cases (GH-16729)

Miss Islington (bot) webhook-mailer at python.org
Sun Dec 1 18:23:37 EST 2019


https://github.com/python/cpython/commit/926eabb6b46106e677d5e1ea25b7bab918da4110
commit: 926eabb6b46106e677d5e1ea25b7bab918da4110
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-12-01T15:23:32-08:00
summary:

bpo-38449: Add URL delimiters test cases (GH-16729)


* bpo-38449: Add tricky test cases

* bpo-38449: Reflect codereview
(cherry picked from commit 2fe4c48917c2d1b40cf063c6ed22ae2e71f4cb62)

Co-authored-by: Dong-hee Na <donghee.na92 at gmail.com>

files:
M Lib/test/test_mimetypes.py

diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py
index adbec8dab4266..f29de8c3a1a28 100644
--- a/Lib/test/test_mimetypes.py
+++ b/Lib/test/test_mimetypes.py
@@ -50,6 +50,21 @@ def test_non_standard_types(self):
         eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None))
         eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
 
+    def test_filename_with_url_delimiters(self):
+        # bpo-38449: URL delimiters cases should be handled also.
+        # They would have different mime types if interpreted as URL as
+        # compared to when interpreted as filename because of the semicolon.
+        eq = self.assertEqual
+        gzip_expected = ('application/x-tar', 'gzip')
+        eq(self.db.guess_type(";1.tar.gz"), gzip_expected)
+        eq(self.db.guess_type("?1.tar.gz"), gzip_expected)
+        eq(self.db.guess_type("#1.tar.gz"), gzip_expected)
+        eq(self.db.guess_type("#1#.tar.gz"), gzip_expected)
+        eq(self.db.guess_type(";1#.tar.gz"), gzip_expected)
+        eq(self.db.guess_type(";&1=123;?.tar.gz"), gzip_expected)
+        eq(self.db.guess_type("?k1=v1&k2=v2.tar.gz"), gzip_expected)
+        eq(self.db.guess_type(r" \"\`;b&b&c |.tar.gz"), gzip_expected)
+
     def test_guess_all_types(self):
         eq = self.assertEqual
         unless = self.assertTrue



More information about the Python-checkins mailing list