Skip to content

Commit 2fe4c48

Browse files
corona10maxking
authored andcommitted
bpo-38449: Add URL delimiters test cases (#16729)
* bpo-38449: Add tricky test cases * bpo-38449: Reflect codereview
1 parent fdafa1d commit 2fe4c48

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Lib/test/test_mimetypes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ def test_non_standard_types(self):
5151
eq(self.db.guess_type('foo.xul', strict=False), ('text/xul', None))
5252
eq(self.db.guess_extension('image/jpg', strict=False), '.jpg')
5353

54+
def test_filename_with_url_delimiters(self):
55+
# bpo-38449: URL delimiters cases should be handled also.
56+
# They would have different mime types if interpreted as URL as
57+
# compared to when interpreted as filename because of the semicolon.
58+
eq = self.assertEqual
59+
gzip_expected = ('application/x-tar', 'gzip')
60+
eq(self.db.guess_type(";1.tar.gz"), gzip_expected)
61+
eq(self.db.guess_type("?1.tar.gz"), gzip_expected)
62+
eq(self.db.guess_type("#1.tar.gz"), gzip_expected)
63+
eq(self.db.guess_type("#1#.tar.gz"), gzip_expected)
64+
eq(self.db.guess_type(";1#.tar.gz"), gzip_expected)
65+
eq(self.db.guess_type(";&1=123;?.tar.gz"), gzip_expected)
66+
eq(self.db.guess_type("?k1=v1&k2=v2.tar.gz"), gzip_expected)
67+
eq(self.db.guess_type(r" \"\`;b&b&c |.tar.gz"), gzip_expected)
68+
5469
def test_guess_all_types(self):
5570
eq = self.assertEqual
5671
unless = self.assertTrue

0 commit comments

Comments
 (0)