Skip to content

bpo-38449: Add URL delimiters test cases #16729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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
Expand Down