Skip to content
Merged
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 @@ -38,8 +38,8 @@ def accepts(
"nbformat" in notebook_content
and "nbformat_minor" in notebook_content
)
except Exception as e:
pass
except (ValueError, LookupError):
return False
finally:
file_stream.seek(cur_pos)

Expand Down
30 changes: 30 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,35 @@ def test_markitdown_llm() -> None:
validate_strings(result, PPTX_TEST_STRINGS)


def test_ipynb_accepts_non_ascii() -> None:
"""IpynbConverter.accepts() must not raise on non-ASCII binary content."""
from markitdown.converters._ipynb_converter import IpynbConverter

converter = IpynbConverter()

# Binary content that is not valid UTF-8 (simulates non-ASCII file)
binary_data = b"\x80\x81\x82\x83"
stream_info = StreamInfo(mimetype="application/json", charset="utf-8")

# Should return False without raising
result = converter.accepts(io.BytesIO(binary_data), stream_info)
assert result is False

# French PDF content (UTF-8 bytes that would crash if decoded as ASCII)
french_bytes = "lettre d'information sur l'événement".encode("utf-8")
stream_info_ascii = StreamInfo(mimetype="application/json", charset="ascii")

result = converter.accepts(io.BytesIO(french_bytes), stream_info_ascii)
assert result is False

# Valid notebook content should still be accepted
notebook_bytes = b'{"nbformat": 4, "nbformat_minor": 5, "cells": []}'
stream_info_json = StreamInfo(mimetype="application/json", charset="utf-8")

result = converter.accepts(io.BytesIO(notebook_bytes), stream_info_json)
assert result is True


def test_epub_metadata_nodevalue():
from defusedxml.minidom import parseString
from markitdown.converters._epub_converter import EpubConverter
Expand Down Expand Up @@ -965,6 +994,7 @@ def test_csv_backslash_without_a_pipe_is_left_alone() -> None:
test_markitdown_exiftool,
test_markitdown_llm_parameters,
test_markitdown_llm,
test_ipynb_accepts_non_ascii,
test_epub_metadata_nodevalue,
]:
print(f"Running {test.__name__}...", end="")
Expand Down
Loading