Skip to content

fix: accept file URI bases for image resources - #4912

Merged
PeterStaar-IBM merged 3 commits into
docling-project:mainfrom
bushidapengyou-cell:codex/fix-file-uri-markdown-images
Oct 25, 2026
Merged

PeterStaar-IBM merged 3 commits into
docling-project:mainfrom
bushidapengyou-cell:codex/fix-file-uri-markdown-images

Conversation

@bushidapengyou-cell

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

Copy link
Copy Markdown
Contributor

Resolves #4911

Accept explicit file:// source URIs when resolving relative images in Markdown and HTML. Local-fetch permissions and path traversal checks remain enforced. Related to #4816.

Review evidence:

Before: file URI bases caused Markdown conversion to fail. HTML kept converting through #4601's tolerance but left the image empty.

After: valid relative images load when local fetching is enabled. Rejected images remain empty, and Markdown conversion continues. Empty file URI paths are rejected.

Tests cover encoded paths, localhost, UNC normalization, local-fetch permissions, and traversal handling. Full UNC resolution is tested only on Windows. No reference data changed.

Validation:

  • File URI regression tests: 10 passed.
  • Affected suites: 207 passed, 1 skipped, 4 known Windows path assertion failures.
  • Local coverage confirms execution of the normalization and Markdown error-handling paths.
  • Applicable prek hooks, Ruff, Tach, dprint, lock validation, and diff checks passed.
  • ty check returned 0 with warnings. Full read-only checks still report existing line-limit and local skill-link issues.

CI follow-up: cc1f6fa6 fixes the Ubuntu UNC test failure by adding a Windows-only condition and a portable normalization test. The previous failure skipped core coverage upload. Updated CI and Codecov results remain to be verified.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

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 20, 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)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Copy link
Copy Markdown
Contributor Author

Fixed the Ubuntu UNC test. Full UNC only on Windows now, plus a cross-platform test. PR updated—waiting on CI.

Signed-off-by: 苍穹外卖-01 <2046083414@qq.com>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working error-handling html issue related to html backend markdown issue related to markdown backend labels Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

This PR adds support for file:// base URIs when resolving relative image paths in Markdown and HTML documents. It also catches ValueError during Markdown image loading to keep conversion working when an image path is invalid.

Topic labels added: bug, markdown, html, error-handling.

CI safety: no concern found. A maintainer must still approve CI.

5 related pull request(s) in the same code
PR State Signal Assessment
#4848 open changes the same code related: PR #4848 modifies Markdown HTML block handling and shares Markdown backend files, but it addresses a different issue.
#3891 open changes the same code related: PR #3891 modifies inline whitespace processing across backend and test files, but it addresses a different issue.
#4921 closed also references issue #4911 related: PR #4921 is a closed pull request that addressed the same issue.
#4816 merged referenced as #4816 related: PR #4816 is a merged pull request that added local path resolution for Markdown images.
#4601 merged referenced as #4601 related: PR #4601 is a merged pull request that added error tolerance for HTML image path traversal.

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 8d53347c60. It read the code and did not run it.

The _local_base_path conversion and the ValueError guard in md_backend.py are correct. The unresolved risk is the broken CI run that produced the low Codecov number; the author says the fixed head has not been verified yet. The reviewer must confirm that the corrected CI run passes all 10 new tests before merging.

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

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

Copy link
Copy Markdown
Member

#4921 (closed in favor of this PR) also covered JATS: jats_backend.py _load_figure_image still returns None when base_path is a file:// URI. Please add that path here, with credit to @taran-dev4u (a Co-authored-by trailer if you reuse their change). @taran-dev4u, a review from you here is very welcome, because you know this code path.

Two more points:

  • _local_base_path: a non-localhost authority (file://server/share/...) becomes //server/... on POSIX, which reads as a local root path. Reject a non-localhost authority outside Windows.
  • md_backend.py _load_image_ref now catches ValueError, so a path-traversal image no longer stops the Markdown conversion. That matches the HTML backend (fix(html): keep converting when a link or image points outside the base directory #4601) and is fine, but say it in the PR description.

Nit: test_local_base_path_normalizes_unc_authority monkeypatches url2pathname, so it tests the implementation. A test with a real path covers the behavior.

@PeterStaar-IBM PeterStaar-IBM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

@PeterStaar-IBM
PeterStaar-IBM merged commit 59acbb6 into docling-project:main Oct 25, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working error-handling html issue related to html backend markdown issue related to markdown backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file:// source_uri is rejected as an image base path

3 participants