Skip to content

Commit 73bcc74

Browse files
committed
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.
1 parent 5fa9055 commit 73bcc74

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ pip-selfcheck.json
1010
pyvenv.cfg
1111
*.pyc
1212
*~
13+
dist/

magic/compat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ def open(flags):
245245

246246

247247
def _create_filemagic(mime_detected, type_detected):
248-
mime_type, mime_encoding = mime_detected.split('; ')
248+
splat = mime_detected.split('; ')
249+
mime_type = splat[0]
250+
if len(splat) == 2:
251+
mime_encoding = splat[1]
252+
else:
253+
mime_encoding = ''
249254

250255
return FileMagic(name=type_detected, mime_type=mime_type,
251256
encoding=mime_encoding.replace('charset=', ''))

0 commit comments

Comments
 (0)