Message164167
The current mimetypes.read_windows_registry() enums the values under HKCR\MIME\Database\Content Type
However, this is the key for mimetype to extension lookups, NOT for extension to mimetype lookups.
As a result, when >1 MIME types are mapped to a particular extension, the last-found entry is used.
For example, both "image/png" and "image/x-png" map to the ".png" file extension.
Unfortunately, what happens is this code finds "image/png", then later finds "image/x-png" and this steals the ".png" extension.
The solution is to use the correct regkey, which is the HKCR root.
This is the correct location for extension-to-mimetype lookups.
What we should do is enum the HKCR root, find all subkeys that start with a dot (i.e. file extensions), then inspect those for a 'Content Type' value.
The attached ZIP contains:
mimetype_flaw_demo.py - this demonstrates the error (due to wrong regkey) and my fix (uses the correct regkey)
mimetypes_fixed.py - My suggested fix to the standard mimetypes.py module. |
|
Date |
User |
Action |
Args |
2012-06-27 16:03:29 | dlchambers | set | recipients:
+ dlchambers |
2012-06-27 16:03:29 | dlchambers | set | messageid: <1340813009.36.0.80214060404.issue15207@psf.upfronthosting.co.za> |
2012-06-27 16:03:28 | dlchambers | link | issue15207 messages |
2012-06-27 16:03:28 | dlchambers | create | |
|