Skip to content

fix(html): decode relative local image URL paths - #5082

Merged
maxmnemonic merged 4 commits into
docling-project:mainfrom
LimbC-C:fix/html-local-image-paths
Nov 17, 2026
Merged

maxmnemonic merged 4 commits into
docling-project:mainfrom
LimbC-C:fix/html-local-image-paths

Conversation

@LimbC-C

@LimbC-C LimbC-C commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #5081.

A local HTML page can contain a valid image URL such as figure%20one.png, but Docling looks for that literal filename and leaves the picture without image data. The same PNG loads through a plain or raw-space filename.

Decode the relative URL path once, only for standalone HTML image loading under a local base. Remove its query and fragment before the existing absolute-path and directory-confinement checks. Keep remote URLs, MHTML archive keys, hyperlinks, and other backends' native-path handling unchanged. The shared resolver's new keyword-only option defaults to false. No dependency or lockfile changes.

Checklist

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary. (No separate example is needed; the issue contains a runnable reproducer.)
  • Tests have been added, if necessary.

Review evidence

  • Base: 9051777f9e420fa3a37df77425b08f22d0bf5981.
  • Real DocumentConverter, local PNG writes, pixel/size checks, caption/text order, and Markdown export with embedded image data. No conversion/parser behavior is mocked.
  • Original production code with the initial nine new cases: 6 failed, 3 passed. The final regression set adds one local-fetch permission control: all 10 pass after the fix.
  • Cases cover spaces, UTF-8 names, a literal %20 filename (decode once), an escaped #, query/fragment handling, encoded traversal and absolute/network-path rejection, disabled fetching, and unchanged remote URL paths/queries through a local HTTP server.
  • Four complete affected modules (test_backend_html.py, test_backend_mhtml.py, test_image_resource_loader.py, test_backend_markdown.py): 234 passed, 4 failed, 1 skipped on Windows. The same four existing path assertions fail with the exact original production files; no old test was edited or skipped to hide them. The failures are test_resolve_relative_path, test_extract_parent_hyperlinks, test_path_traversal_blocked_in_resolve_relative_path, and test_valid_local_paths_still_work.
  • Actual make SHELL=sh.exe validate with GNU Make 4.4.1 and Git Bash: 11 applicable hooks passed, 5 inapplicable hooks skipped, including Ruff, ty, Tach, module coverage, license checks, and file-size limits.
  • Frozen Windows CI dependency recipe: uv sync --frozen --group dev --all-packages --no-group docs --no-group examples. Python 3.12.14; docling/docling-slim 2.144.0; docling-core 2.104.0. Test HTTP traffic stays local; the process bypasses the Windows system proxy for those server fixtures. No model weights were downloaded or run.

No reference data was regenerated. The whole repository/model suite and Linux/macOS runs were not performed. The four Windows baseline failures remain outside this repair.

AI assistance: Codex assisted with investigation, implementation, tests, and this description. No independent human review is claimed.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @LimbC-C, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 29, 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)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working html issue related to html backend labels Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The HTML backend now decodes percent-escaped relative local image paths, so figure%20one.png loads figure one.png. The EPUB backend now encodes image paths again so the decoding happens only once.

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

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

I found no defect that should stop the merge. I traced the decoded-path flow in docling/backend/utils/image_resource_loader.py for a local base, and confinement still runs on the decoded path. Encoded .. and encoded // are rejected, and MHTML, remote URLs, and hyperlinks keep their old paths because the new flag is set only when _mhtml_resources is None. The tests cover the defect. The only side effect is that a local file whose name has a raw ? or #, or a literal %XX sequence, no longer loads from an unencoded src. This matches browser behavior, and the PR states it.

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 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LimbC-C

LimbC-C commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

I checked Run CI attempt 2 at 95fcff94a6c6cb4ac1dfe158fd6046d69900fe8c. The failing job is run-examples-light (3.10): docs/examples/enrich_doclingdocument.py:138 initializes DocumentPictureClassifier, then the HuggingFace metadata/download stack raises httpx.ReadError: [SSL: UNEXPECTED_EOF_WHILE_READING] unexpected eof while reading. The example, model-download source, workflow and lockfile are byte-identical to the PR base. No HTML path-resolution frame appears in that traceback; I have not rerun the original-base example or established the remote SSL root cause.

The core-test job passed 3,699 tests, with 35 skipped, including all 10 new HTML regressions. The OCR/VLM/PDF/ASR jobs, lint/Tach, and Docs CI also succeeded. The overall Run CI is still failed because of the example job. No code change or rerun was made on the basis of this network traceback.

Investigation and this summary were AI-assisted; no independent human review is claimed.

@github-actions github-actions Bot removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Nov 7, 2026
@LimbC-C

LimbC-C commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Synced with main at 1e26b84c5f5690128ddcd65a20a5d7ffb9e80dcd; new head 3e23453e094ee144cfd10cecad505a3eb950be75 (history-preserving DCO merge).

Retained the updated upstream picture/caption parent-child structure and CMYK handling. The local HTML image URL-decoding opt-in remains confined to the existing resolver call; upstream tests and the original ten URL regression cases are preserved.

Local Windows/Python3.12 validation on this exact head:

  • HTML/image-resource/MHTML modules: 224 passed, 4 failed, 1 skipped. All ten original URL cases and the CMYK/caption/MHTML cases pass.
  • The four failures are Windows path-separator/drive assertions; all four also fail on a separate clean checkout of the exact upstream commit in the same environment. No expected results were changed. The skipped browser-render test uses the upstream importorskip because Playwright is unavailable.
  • make validate: 15 checks passed, 1 skipped. Actual merge-commit hooks: 11 passed, 5 skipped; no hook bypass.

Local HTTP fixtures were run with NO_PROXY=*; the earlier proxy-misconfigured run is retained in the evidence. This is focused validation, not a full-repository or new-head CI success claim. AI assistance was used for the sync and independent static review; no human review is claimed.

@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Nov 7, 2026

@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 changes since 95fcff94a6 at 3e23453e09. It read the code and did not run it.

The new commits touch none of the PR's files: docling/backend/html_backend.py, docling/backend/utils/image_resource_loader.py, docs/usage/advanced_options.md and tests/test_backend_html.py are unchanged since the earlier review. They only merge unrelated base-branch changes: CI scripts, plans, changelog and Makefile. I found no new point to report.

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 Nov 7, 2026
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Nov 11, 2026
maxmnemonic
maxmnemonic previously approved these changes Nov 17, 2026

@maxmnemonic maxmnemonic 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!

EPUB decoded each image src to find its archive entry and passed the
decoded path to the HTML backend, so the HTML backend needed a private
flag to skip its own URL decoding. Encode the path again instead, so
the HTML backend reads every local image src as a URL and decodes it
once. Remove the flag.

Signed-off-by: Panos Vagenas <[email protected]>
@github-actions github-actions Bot removed the ai:ci-safe AI triage found no CI-safety concern (advisory) label Nov 17, 2026

@vagenas vagenas 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.

Thanks @LimbC-C, I pushed a small follow-up: EPUB now passes URL-encoded image src values, so the private _decode_local_image_urls flag is no longer needed.

@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Nov 17, 2026

@maxmnemonic maxmnemonic 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.

Great!

@maxmnemonic
maxmnemonic merged commit 2e02cfe into docling-project:main Nov 17, 2026
34 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) bug Something isn't working html issue related to html backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML image loading does not decode percent-escaped local filenames

4 participants