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

Fix wrong mimetype for docx files #2416

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

gamerlv
Copy link
Contributor

@gamerlv gamerlv commented Jun 30, 2023

Description

This PR seeks to resolve #1753, allowing files created by the word2007 writer to be detected as word files and not application/octet-stream. I ran into this issue while working on file upload using Laravel's build-in file validation.

Based on this magic file, I've deduced how the word file mimetype is detected.

The file needs to be a zip, inside the first two filenames need to match a regex, then the 3rd and 4th filenames are inspected to see what path they start with. When either matches word/ the file is determined to be a word 2007 file.
Before this process would find docProps/, which does pass the regex, but not match an office mimetype, causing the file to get the type MSOOXML application/octet-stream.

I've added a passing test to ensure this does not pop up again.
I am unsure what documentation needs to be updated for a bugfix.

Fixes #1753

Checklist:

  • I have run composer run-script check --timeout=0 and no errors were reported
  • The new code is covered by unit tests (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes

@Progi1984 Progi1984 merged commit 409172c into PHPOffice:master Aug 12, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants