]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38449: Add URL delimiters test cases (#16729)
authorDong-hee Na <donghee.na92@gmail.com>
Sun, 1 Dec 2019 23:06:28 +0000 (08:06 +0900)
committerAbhilash Raj <maxking@users.noreply.github.com>
Sun, 1 Dec 2019 23:06:28 +0000 (15:06 -0800)
* bpo-38449: Add tricky test cases

* bpo-38449: Reflect codereview

Lib/test/test_mimetypes.py

index bfd5eeedaa77b47ea5f12772f9f42a9314df1690..a5a06b189dec4f088cb6535f07c9031216cea1e3 100644 (file)
@@ -51,6 +51,21 @@ class MimeTypesTestCase(unittest.TestCase):
         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