diff options
author | Adam Hupp <adam@hupp.org> | 2021-09-02 15:19:16 -0700 |
---|---|---|
committer | Adam Hupp <adam@hupp.org> | 2021-09-02 15:19:16 -0700 |
commit | 73bcc7482bf3e6d1f6a74a91bf9689b289a88910 (patch) | |
tree | dab68fcc3ada543581e44dd2a76b99ab9db3aabf | |
parent | 5fa9055bdc4159ebab0699ae0429de29ae171267 (diff) | |
download | python-magic-73bcc7482bf3e6d1f6a74a91bf9689b289a88910.tar.gz |
Fix compat mode handling with empty mime string
I can't repro this, but PR #250 suggests that some versions of
libmagic will return a mimetype that doesn't include a charset,
leading to an exception. Fall back to an empty charset in this case.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | magic/compat.py | 7 |
2 files changed, 7 insertions, 1 deletions
@@ -10,3 +10,4 @@ pip-selfcheck.json pyvenv.cfg *.pyc *~ +dist/ diff --git a/magic/compat.py b/magic/compat.py index e2d71ee..07fad45 100644 --- a/magic/compat.py +++ b/magic/compat.py @@ -245,7 +245,12 @@ none_magic.load() def _create_filemagic(mime_detected, type_detected): - mime_type, mime_encoding = mime_detected.split('; ') + splat = mime_detected.split('; ') + mime_type = splat[0] + if len(splat) == 2: + mime_encoding = splat[1] + else: + mime_encoding = '' return FileMagic(name=type_detected, mime_type=mime_type, encoding=mime_encoding.replace('charset=', '')) |