diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf31559..75cb8790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to - 🔥(global) remove notion of workspace +### Fixed + +- 🐛(backend) manage ole2 compound document format + ## [v0.12.0] - 2026-02-06 ### Added @@ -292,4 +296,4 @@ and this project adheres to [v0.2.0]: https://github.com/suitenumerique/drive/releases/v0.2.0 [v0.1.1]: https://github.com/suitenumerique/drive/releases/v0.1.1 [v0.1.0]: https://github.com/suitenumerique/drive/releases/v0.1.0 -## [v0.11.1] - 2026-01-13 \ No newline at end of file +## [v0.11.1] - 2026-01-13 diff --git a/src/backend/core/api/utils.py b/src/backend/core/api/utils.py index fa2b31cd..2578e5da 100644 --- a/src/backend/core/api/utils.py +++ b/src/backend/core/api/utils.py @@ -202,6 +202,7 @@ def detect_mimetype(file_buffer: bytes, filename: str | None = None) -> str: # Generic/unreliable MIME types that we should try to improve generic_types = { "application/octet-stream", + "application/x-ole-storage", # used by .xls, .doc and .ppt "application/zip", "text/plain", } diff --git a/src/backend/core/tests/test_api_utils_detect_mimetype.py b/src/backend/core/tests/test_api_utils_detect_mimetype.py index 8f02c5f5..4d77182a 100644 --- a/src/backend/core/tests/test_api_utils_detect_mimetype.py +++ b/src/backend/core/tests/test_api_utils_detect_mimetype.py @@ -144,3 +144,15 @@ def test_detect_mimetype_powerpoint_ppt(): "application/vnd.ms-powerpoint", "application/mspowerpoint", ] + + +def test_detect_mimetype_ole_storage(): + """ + Microsoft files .xls .doc .ppt can use the mimetype application/x-ole-storage + for Microsoft OLE2/Compound File Binary Format. In that case we want to rely on the extension + """ + + xls_ole_content = b"\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1" + mimetype = utils.detect_mimetype(xls_ole_content, filename="document.xls") + + assert mimetype == "application/vnd.ms-excel"