Skip to content

Commit 4e29325

Browse files
committed
gh-146343: Fix conflicting built-in MIME type mappings
1 parent b1bb67f commit 4e29325

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

‎Doc/whatsnew/3.16.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,10 @@ mimetypes
12411241
Valid extensions must now start with a ``'.'`` or be empty;
12421242
undotted extensions raise a :exc:`ValueError`.
12431243
(Contributed by Nikita Sobolev in :gh:`149720`.)
1244-
* Add more MIME types
1244+
1245+
* Add more built-in MIME types. The ``.vcf`` extension now maps to
1246+
``text/vcard``. Passing ``strict=False`` to :func:`mimetypes.guess_extension`
1247+
still returns ``.vcf`` for the legacy ``text/x-vcard`` type.
12451248
(Contributed by Charlie Lin in :gh:`146344`.)
12461249

12471250
shutil

‎Lib/mimetypes.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ def _default_mime_types():
497497
'.dcm' : 'application/dicom',
498498
'.efi' : 'application/efi',
499499
'.epub' : 'application/epub+zip',
500+
'.gml' : 'application/gml+xml',
500501
'.gz' : 'application/gzip',
501502
'.json' : 'application/json',
502503
'.webmanifest': 'application/manifest+json',
@@ -590,6 +591,7 @@ def _default_mime_types():
590591
'.rdf' : 'application/xml',
591592
'.wsdl' : 'application/xml',
592593
'.xpdl' : 'application/xml',
594+
'.ent' : 'application/xml-external-parsed-entity',
593595
'.yaml' : 'application/yaml',
594596
'.yml' : 'application/yaml',
595597
'.zip' : 'application/zip',
@@ -665,8 +667,7 @@ def _default_mime_types():
665667
'.gltf' : 'model/gltf+json',
666668
'.glb' : 'model/gltf-binary',
667669
'.stl' : 'model/stl',
668-
'.appcache' : 'text/cache-manifest',
669-
'.manifest' : 'text/cache-manifest',
670+
'.appcache': 'text/cache-manifest',
670671
'.ics' : 'text/calendar',
671672
'.ifb' : 'text/calendar',
672673
'.cql' : 'text/cql',
@@ -699,11 +700,10 @@ def _default_mime_types():
699700
'.ttl' : 'text/turtle',
700701
'.uri' : 'text/uri-list',
701702
'.uris' : 'text/uri-list',
702-
'.vcard' : 'text/vcard',
703703
'.vcf' : 'text/vcard',
704+
'.vcard' : 'text/vcard',
704705
'.ascii' : 'text/vnd.ascii-art',
705706
'.curl' : 'text/vnd.curl',
706-
'.gml' : 'text/vnd.gml',
707707
'.gv' : 'text/vnd.graphviz',
708708
'.vtt' : 'text/vtt',
709709
'.wgsl' : 'text/wgsl',
@@ -712,9 +712,7 @@ def _default_mime_types():
712712
'.etx' : 'text/x-setext',
713713
'.sgm' : 'text/x-sgml',
714714
'.sgml' : 'text/x-sgml',
715-
'.vcf' : 'text/x-vcard',
716715
'.xml' : 'text/xml',
717-
'.ent' : 'text/xml-external-parsed-entity',
718716
'.mkv' : 'video/matroska',
719717
'.mk3d' : 'video/matroska-3d',
720718
'.mp4' : 'video/mp4',
@@ -744,6 +742,7 @@ def _default_mime_types():
744742
'.pict': 'image/pict',
745743
'.pct' : 'image/pict',
746744
'.pic' : 'image/pict',
745+
'.vcf' : 'text/x-vcard',
747746
'.xul' : 'text/xul',
748747
}
749748

‎Lib/test/test_mimetypes.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ def test_default_data(self):
385385
eq(self.db.guess_file_type("foo.tar.Z"), ("application/x-tar", "compress"))
386386
eq(self.db.guess_file_type("foo.tar.bz2"), ("application/x-tar", "bzip2"))
387387
eq(self.db.guess_file_type("foo.tar.xz"), ("application/x-tar", "xz"))
388+
eq(self.db.guess_file_type("foo.vcf"), ("text/vcard", None))
389+
eq(self.db.guess_file_type("foo.vcard"), ("text/vcard", None))
390+
eq(self.db.guess_extension("text/vcard"), ".vcf")
391+
eq(self.db.guess_file_type("foo.gml"), ("application/gml+xml", None))
392+
eq(self.db.guess_file_type("foo.ent"),
393+
("application/xml-external-parsed-entity", None))
394+
eq(self.db.guess_file_type("foo.appcache"), ("text/cache-manifest", None))
395+
eq(self.db.guess_file_type("foo.manifest"), (None, None))
388396

389397
def test_data_urls(self):
390398
eq = self.assertEqual
@@ -412,6 +420,8 @@ def test_non_standard_types(self):
412420
eq(self.db.guess_file_type('foo.invalid', strict=False), (None, None))
413421
eq(self.db.guess_extension('image/jpeg', strict=False), '.jpg')
414422
eq(self.db.guess_extension('image/JPEG', strict=False), '.jpg')
423+
eq(self.db.guess_file_type('foo.vcf', strict=False), ('text/vcard', None))
424+
eq(self.db.guess_extension('text/x-vcard', strict=False), '.vcf')
415425

416426
def test_filename_with_url_delimiters(self):
417427
# bpo-38449: URL delimiters cases should be handled also.

‎Misc/NEWS.d/next/Library/2026-03-23-20-37-02.gh-issue-146343.JnXJVB.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Add the following MIME types with file extensions:
2-
``.appcache`` and ``.manifest`` for ``text/cache-manifest``
2+
``.appcache`` for ``text/cache-manifest``
33
``.ics`` and ``.ifb`` for ``text/calendar``
44
``.cql`` for ``text/cql``
55
``.csvs`` for ``text/csv-schema``
@@ -13,10 +13,10 @@ Add the following MIME types with file extensions:
1313
``.spdx`` for ``text/spdx``
1414
``.ttl`` for ``text/turtle``
1515
``.uri`` and ``.uris`` for ``text/uri-list``
16-
``.vcard`` and ``.vcf`` for ``text/vcard``
16+
``.vcf`` and ``.vcard`` for ``text/vcard``
1717
``.ascii`` for ``text/vnd.ascii-art``
1818
``.curl`` for ``text/vnd.curl``
19-
``.gml`` for ``text/vnd.gml``
19+
``.gml`` for ``application/gml+xml``
2020
``.gv`` for ``text/vnd.graphviz``
2121
``.wgsl`` for ``text/wgsl``
22-
``.ent`` for ``text/xml-external-parsed-entity``
22+
``.ent`` for ``application/xml-external-parsed-entity``

0 commit comments

Comments
 (0)