Skip to content

fix(images): complete JATS file URI figure loading - #5017

Open
bushidapengyou-cell wants to merge 2 commits into
docling-project:mainfrom
bushidapengyou-cell:fix/jats-file-uri-follow-up
Open

bushidapengyou-cell wants to merge 2 commits into
docling-project:mainfrom
bushidapengyou-cell:fix/jats-file-uri-follow-up

Conversation

@bushidapengyou-cell

@bushidapengyou-cell bushidapengyou-cell commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #5016. Follow-up to #4912 and the JATS work identified by @taran-dev4u in #4921.

Support local file URI sources in JATS, reject root-only JATS file URIs and non-localhost authorities outside Windows, and preserve article content when figure decoding raises OSError. Fetch permissions and directory confinement remain unchanged.

The separate Makefile commit aligns the line limit with the existing CI hook. It is independent of the image fix and can be split out if preferred.

Checklist:

  • Documentation updated.
  • Regression tests added.

Review evidence:

Verified image pixels, caption links, body ownership/order, and embedded Markdown export. No reference data changed.

Linux/Python 3.10: 333 passed, 3 skipped, including POSIX authority regressions:

PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 NO_PROXY='*' uv run --no-sync python -m coverage run --branch --source=docling.backend.xml.jats_backend,docling.backend.utils.image_resource_loader -m pytest -p no:cacheprovider -o addopts= tests/test_image_resource_loader.py tests/test_backend_jats.py tests/test_backend_jats_sub_articles.py tests/test_backend_jats_images.py tests/test_image_resource_file_uri.py tests/test_backend_markdown.py tests/test_backend_html.py tests/test_check_skill_routes.py -q --tb=short

UV_NO_SYNC=1 make check
UV_NO_SYNC=1 make validate

Both Make targets passed; non-blocking ty diagnostics remain.

Local Windows/Python 3.12: 320 passed, 4 failed, 5 skipped, with process-scoped PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 and NO_PROXY=*:

uv run --no-sync pytest -p no:cacheprovider -o addopts= tests/test_image_resource_loader.py tests/test_backend_jats.py tests/test_backend_jats_sub_articles.py tests/test_backend_jats_images.py tests/test_image_resource_file_uri.py tests/test_backend_markdown.py tests/test_backend_html.py -q --tb=short

The same 4 HTML path assertion failures reproduce on the base. These are local results; full online CI awaits maintainer action. macOS was not tested.

Signed-off-by: 苍穹外卖-01 <2046083414@qq.com>
Signed-off-by: 苍穹外卖-01 <2046083414@qq.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @bushidapengyou-cell, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@bushidapengyou-cell bushidapengyou-cell changed the title Fix/jats file uri follow up fix(images): complete JATS file URI figure loading Oct 26, 2026
@github-actions github-actions Bot added ai:ci-needs-care AI triage: check CI-safety findings before you approve CI bug Something isn't working documentation Improvements or additions to documentation tests issue related to changes needed in the tests xml issue related to supported schema-specific XML formats labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit db3bbb8813. The analysis read the diff only. It did not run code from this pull request.

This pull request adds support for local file:// URIs in the JATS backend. It also restricts non-localhost file URI authorities to Windows UNC paths and handles figure decoding errors.

Topic labels added: xml, bug, documentation, tests.

CI safety: needs maintainer care before you approve CI.

  • Makefile: changes local and CI commands
4 related pull request(s) in the same code
PR State Signal Assessment
#4683 open changes the same code related: PR #4683 normalizes image modes for PNG export in ImageResourceLoader, while this pull request improves file URI handling and JATS figure loading.
#4866 open changes the same code related: PR #4866 extracts license and funding metadata in JatsDocumentBackend, while this pull request processes figure images.
#4921 closed referenced as #4921 related: PR #4921 is a closed pull request that attempted to add file URI support for relative image paths.
#4912 merged referenced as #4912 related: PR #4912 is a merged pull request that added initial file URI support in ImageResourceLoader, which this pull request refactors and extends.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot 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.

AI first review (advisory): no blocker found

This review covers the full diff at db3bbb8813. It read the code and did not run it.

The logic changes in _load_figure_image and normalize_local_base_path are correct and well-tested. The only merge blocker is the PR title, which does not follow the fix(...): conventional-commit format that Mergify requires. No code defects were found.

A maintainer makes the merge decision. This review never approves the pull request.

or self.base_path is None
or not ImageResourceLoader.is_local_path(self.base_path)
):
if not self.options.fetch_images or self.base_path is None:

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.

question: JATS images require enable_local_fetch=True but the gate does not check it

The old guard checked is_local_path(self.base_path); the new guard skips the enable_local_fetch flag entirely. The permission is still enforced later inside ImageResourceLoader.load_image_data (which raises OperationNotAllowed, caught in create_image_ref and silently swallowed). But the function now calls normalize_local_base_path, Path.is_file, and emits warnings for root-URI cases even when enable_local_fetch=False. The test test_local_permission_prevents_image_bytes covers only the case where fetch_images=True and enable_local_fetch=False; it patches builtins.open to prove bytes are not read, which is correct. The normalize_local_base_path and is_file calls are not patched, so they do run. This is not a security regression (bytes are never read without the flag) but it is a behavioral change: the function now touches the filesystem even when local fetch is disabled. Confirm this is acceptable, or add an early return when not self.options.enable_local_fetch.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-needs-care AI triage: check CI-safety findings before you approve CI ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working documentation Improvements or additions to documentation tests issue related to changes needed in the tests xml issue related to supported schema-specific XML formats

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JATS skips figure images with a file URI source

1 participant