Skip to content

fix: IpynbConverter.accepts() catches UnicodeDecodeError on non-decodable content (fixes #1894) - #1929

Merged
Adam Fourney (afourney) merged 4 commits into
microsoft:mainfrom
hanhan761:fix-1894-ipynb-unicode-decode
Sep 2, 2026
Merged

Adam Fourney (afourney) merged 4 commits into
microsoft:mainfrom
hanhan761:fix-1894-ipynb-unicode-decode

Conversation

@hanhan761

Copy link
Copy Markdown
Contributor

Summary

IpynbConverter.accepts() raises UnicodeDecodeError when the file stream contains non-ASCII bytes that cannot be decoded as UTF-8. This crash propagates up and fails the entire conversion pipeline, even when the file is not a Jupyter notebook.

Fix

Wrapped the .decode() call in accepts() with except (UnicodeDecodeError, ValueError) to gracefully return False when the content cannot be decoded.

Issue

Fixes #1894

Verification

  • Tested with non-decodable binary content
  • Verified valid notebooks still detected correctly
  • Added unit test test_ipynb_accepts_handles_non_ascii_content

…files

Wrap the decode block in accepts() with try/except (UnicodeDecodeError,
ValueError) so that non-ASCII files (e.g. French PDFs) whose MIME type
starts with 'application/json' do not crash the conversion pipeline.

Fixes microsoft#1894
@hanhan761
hanhan761 force-pushed the fix-1894-ipynb-unicode-decode branch from 84086aa to 49328c0 Compare May 30, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The narrowed handler allows unknown charset names to raise LookupError and abort conversion.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Improves notebook detection for non-decodable content.

Changes:

  • Narrows decoding exception handling in IpynbConverter.accepts().
  • Adds coverage for invalid and valid notebook content.
File summaries
File Description
packages/markitdown/src/markitdown/converters/_ipynb_converter.py Handles decoding failures during notebook detection.
packages/markitdown/tests/test_module_misc.py Tests binary, ASCII-incompatible, and valid notebook content.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/markitdown/src/markitdown/converters/_ipynb_converter.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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 this pull request may close these issues.

bug: IpynbConverter.accepts() raises UnicodeDecodeError on non-ASCII files (French PDFs, etc.)

3 participants