summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hupp <adam@hupp.org>2021-09-02 15:19:16 -0700
committerAdam Hupp <adam@hupp.org>2021-09-02 15:19:16 -0700
commit73bcc7482bf3e6d1f6a74a91bf9689b289a88910 (patch)
treedab68fcc3ada543581e44dd2a76b99ab9db3aabf
parent5fa9055bdc4159ebab0699ae0429de29ae171267 (diff)
downloadpython-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--.gitignore1
-rw-r--r--magic/compat.py7
2 files changed, 7 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 0346a85..111565e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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=', ''))