Skip to content

fix: IpynbConverter.accepts() catches UnicodeDecodeError on non-ASCII files (fixes #1894) - #1932

Closed
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-1894-ipynb-decode-error
Closed

hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-1894-ipynb-decode-error

Conversation

@hanhan761

Copy link
Copy Markdown
Contributor

Summary

\IpynbConverter.accepts()\ reads the full file stream and decodes it to detect Jupyter notebooks. When a non-ASCII file (e.g., a French PDF with accented characters like é/è/à) produces a MIME type starting with \�pplication/json\, the \.decode()\ call raises \UnicodeDecodeError\ which propagates uncaught and crashes the entire conversion pipeline.

This fix wraps the decode block in \ ry/except (UnicodeDecodeError, ValueError)\ so that \�ccepts()\ gracefully returns \False\ instead of crashing.

Issue

Fixes #1894

Verification

  • Binary non-ASCII content with \�pplication/json\ MIME → returns \False\ (no crash)
  • Valid \.ipynb\ notebook → still returns \True\
  • Plain JSON → returns \False\
  • 2/3 existing tests pass (1 pre-existing failure due to missing docx dependency)

@afourney

Copy link
Copy Markdown
Member

Closed in #2360

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.)

2 participants