Skip to content

fix(ipynb): preserve JSON documents that mention notebook fields - #2473

Open
Oscar (Oscar-Williams) wants to merge 1 commit into
microsoft:mainfrom
Oscar-Williams:fix/ipynb-json-detection
Open

fix(ipynb): preserve JSON documents that mention notebook fields#2473
Oscar (Oscar-Williams) wants to merge 1 commit into
microsoft:mainfrom
Oscar-Williams:fix/ipynb-json-detection

Conversation

@Oscar-Williams

Copy link
Copy Markdown

An ordinary JSON document such as {"description": "nbformat_minor describes a notebook version"} currently converts to empty Markdown. IpynbConverter.accepts() matches notebook field names anywhere in the text, then conversion treats the missing cells as an empty notebook and prevents the plain-text fallback.

Probe the parsed top-level JSON fields before accepting it as a notebook. Check JSON before trusting a .ipynb extension, since format detection can infer that extension for JSON schema fragments too. Preserve BOM/charset handling and stream position, and decline malformed or excessively nested JSON without interrupting conversion.

Validation on Windows, Python 3.11.7:

  • The same 17 new regression cases give 12 failed / 5 passed on main and 17 passed with this fix.
  • hatch test --python 3.11 -q --tb=short: 859 passed, 34 skipped, using the project's CI skip mode (GITHUB_ACTIONS=true, PYTHONUTF8=1).
  • pre-commit run --all-files and git diff --check: passed.

Implemented and tested with Codex assistance.

@Oscar-Williams

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

1 participant