Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__detect_mime_type is broken #35

Open
weddige opened this issue Nov 16, 2022 · 1 comment · May be fixed by #36
Open

__detect_mime_type is broken #35

weddige opened this issue Nov 16, 2022 · 1 comment · May be fixed by #36

Comments

@weddige
Copy link

weddige commented Nov 16, 2022

__detect_mime_type has a bug in line 66/67:

ezodf/ezodf/document.py

Lines 56 to 68 in f9675c1

def __detect_mime_type(file_manager):
mime_type = file_manager.get_text('mimetype')
if mime_type is not None:
return mime_type
# Fall-through to next mechanism
entry = file_manager.manifest.find('/')
if entry is not None:
mime_type = entry.get(CN('manifest:media-type'))
else:
# use file ext name
ext = os.path.splitext(file_manager.zipname)[1]
mime_type = MIMETYPES[ext]
return mime_type

os.path.splitext returns the file extension with a leading dot (e. g. .ods). But MIMETYPES only contains the extensions without the dot:

'ots': "application/vnd.oasis.opendocument.spreadsheet-template",

@kenchou
Copy link
Contributor

kenchou commented Nov 22, 2022

emmm, This function is introduced by me...

ext = os.path.splitext(file_manager.zipname)[1]
should be
ext = os.path.splitext(file_manager.zipname)[1][1:]

I will create a PR later.

@kenchou kenchou linked a pull request Nov 22, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants