Skip to content

fix(markdown): escape referenced figures' filepaths and ensure cross-platform path handling (Windows / POSIX) - #698

Open
the-zucc wants to merge 5 commits into
docling-project:mainfrom
the-zucc:main
Open

fix(markdown): escape referenced figures' filepaths and ensure cross-platform path handling (Windows / POSIX)#698
the-zucc wants to merge 5 commits into
docling-project:mainfrom
the-zucc:main

Conversation

@the-zucc

@the-zucc the-zucc commented Jul 30, 2026

Copy link
Copy Markdown

#182 caused a regression in which the behavior introduced in #122 was removed.

I'm therefore proposing that we re-add the change, slightly modified for both POSIX and Windows path support.

One edge-case identified is the obvious case where the destination path is a filename containing a backslash. I've mentioned the limitation in the docstring.

Partial fix for docling-project/docling#3617

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @the-zucc, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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

I, Laurier Lavoie-Giasson <laurier@laurier.dev>, hereby add my Signed-off-by to this commit: 513a8d5

Signed-off-by: Laurier Lavoie-Giasson <laurier@laurier.dev>
@the-zucc the-zucc changed the title fix: escape filepaths and ensure proper path handling (Windows / POSIX) fix: escape referenced figures' filepaths and ensure cross-platform path handling (Windows / POSIX) Jul 30, 2026
Laurier Lavoie-Giasson added 2 commits July 30, 2026 00:27
I, Laurier Lavoie-Giasson <laurier@laurier.dev>, hereby add my Signed-off-by to this commit: 513a8d5
I, Laurier Lavoie-Giasson <laurier@laurier.dev>, hereby add my Signed-off-by to this commit: b5225cd

Signed-off-by: Laurier Lavoie-Giasson <laurier@laurier.dev>
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@the-zucc the-zucc changed the title fix: escape referenced figures' filepaths and ensure cross-platform path handling (Windows / POSIX) fix(markdown): escape referenced figures' filepaths and ensure cross-platform path handling (Windows / POSIX) Aug 5, 2026

@ceberam ceberam 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 @the-zucc for suggesting this PR and resolve the regression!

I've just added some few minor comments.
Please, rebase to main to solve the conflict with test/test_serialization.py

Comment on lines +726 to +729
_URI_KEEP_CHARS: str = "/%:@+,;=~$!&'*"

# Matches the drive prefix of an absolute Windows path, e.g. ``C:/``.
_WINDOWS_DRIVE_RE: re.Pattern = re.compile(r"[A-Za-z]:/")

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.

_URI_KEEP_CHARS and _WINDOWS_DRIVE_RE are defined inside the method body and both constants are reconstructed on every call. You can move them out, at class level. You can also annotate them as Final.



# A link destination to encode, paired with its expected encoding.
_EscapeCase = tuple[Union[AnyUrl, PurePath], str]

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.

Minor comment: use TypeAlias as per PEP 613.

Comment on lines +722 to +725
# Characters that survive percent-encoding in a link destination.
# The RFC 3986 reserved characters that carry meaning in a URI, plus ``%`` so that an
# already-encoded destination is not encoded a second time. Whitespace and parentheses
# are deliberately absent: they would end a Markdown inline link.

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.

Could you please:

  • tighten the prose to reduce verbosity
  • instead of inline comments, add this information as docstrings for these constants in google style

Comment on lines +712 to +713
Known limitation: behavior is unknown if value is a POSIX filename, containing
an actual backslash in the filename.

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.

The behavior is wrong but deterministic: the backslash is misinterpreted as a separator. But this is harmless in practice. Please, accept this suggestion:

Suggested change
Known limitation: behavior is unknown if value is a POSIX filename, containing
an actual backslash in the filename.
Known limitation: a backslash in a `PosixPath` string is ambiguous.
It may be a Windows separator surviving a JSON round-trip (correct to
convert) or a literal filename character (where converting it to `/`
would split one component into two). The two cases are indistinguishable
from `str()`. In practice this is not a concern because `ImageRef.uri`
is always populated from native filesystem operations, so a `PosixPath`
can only carry a literal backslash if the caller explicitly constructed one.

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.

2 participants