From b43eaa68e05a57614a933c590f183b282604d1c4 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Sun, 13 Oct 2019 02:03:19 +0900 Subject: [PATCH 1/2] bpo-38449: Add tricky test cases --- Lib/test/test_mimetypes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index bfd5eeedaa77b4..213d4c637116b0 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -51,6 +51,12 @@ 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_tricky_cases(self): + # bpo-38449: Tricky cases should be handled also. + eq = self.assertEqual + eq(self.db.guess_type(";1.tar.gz"), ('application/x-tar', 'gzip')) + eq(self.db.guess_type(r" \"\`;b&b&c |.tar.gz"), ('application/x-tar', 'gzip')) + def test_guess_all_types(self): eq = self.assertEqual unless = self.assertTrue From bc52ae569a1d1a1076a27b3eb5e99ea1fe5341bf Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Sun, 13 Oct 2019 02:23:32 +0900 Subject: [PATCH 2/2] bpo-38449: Reflect codereview --- Lib/test/test_mimetypes.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py index 213d4c637116b0..a5a06b189dec4f 100644 --- a/Lib/test/test_mimetypes.py +++ b/Lib/test/test_mimetypes.py @@ -51,11 +51,20 @@ 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_tricky_cases(self): - # bpo-38449: Tricky cases should be handled also. + 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 - eq(self.db.guess_type(";1.tar.gz"), ('application/x-tar', 'gzip')) - eq(self.db.guess_type(r" \"\`;b&b&c |.tar.gz"), ('application/x-tar', 'gzip')) + 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