Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ def accepts(
mimetype = (stream_info.mimetype or "").lower()
extension = (stream_info.extension or "").lower()

if extension in ACCEPTED_XLS_FILE_EXTENSIONS:
return True
# Some upstream systems label every legacy Office Compound File as
# application/vnd.ms-excel, including Word .doc files. When the
# extension is known, use it as the discriminator so a .doc is not
# handed to xlrd. MIME type remains a fallback for extensionless input.
if extension:
return extension in ACCEPTED_XLS_FILE_EXTENSIONS

for prefix in ACCEPTED_XLS_MIME_TYPE_PREFIXES:
if mimetype.startswith(prefix):
Expand Down
21 changes: 21 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,27 @@ def test_exceptions() -> None:
assert type(exc_info.value.attempts[0].converter).__name__ == "PptxConverter"


def test_legacy_doc_with_excel_mimetype_is_not_sent_to_xls_converter(
monkeypatch: pytest.MonkeyPatch,
) -> None:
markitdown = MarkItDown()
monkeypatch.setattr(
markitdown._magika,
"identify_stream",
MagicMock(return_value=SimpleNamespace(status="unknown")),
)

with pytest.raises(UnsupportedFormatException):
markitdown.convert_stream(
io.BytesIO(b"\x00\x01\x02\x03" * 64),
stream_info=StreamInfo(
filename="legacy.doc",
extension=".doc",
mimetype="application/vnd.ms-excel",
),
)


def test_markitdown_llm_parameters() -> None:
"""Test that LLM parameters are correctly passed to the client."""
mock_client = MagicMock()
Expand Down
13 changes: 13 additions & 0 deletions packages/markitdown/tests/test_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ def entity(name: str, content: bytes) -> bytes:
render.assert_not_called()


def test_xls_acceptance_prefers_known_extension_over_mimetype() -> None:
converter = XlsConverter()
excel_mimetype = "application/vnd.ms-excel"

assert converter.accepts(
io.BytesIO(), StreamInfo(extension=".xls", mimetype=excel_mimetype)
)
assert converter.accepts(io.BytesIO(), StreamInfo(mimetype=excel_mimetype))
assert not converter.accepts(
io.BytesIO(), StreamInfo(extension=".doc", mimetype=excel_mimetype)
)


def test_missing_dependencies_and_legacy_xls_stay_separate(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand Down