fix: percent-encode attachment filenames in image links - #34
Merged
Merged
Conversation
blaipr
force-pushed
the
fix/attachment-filename-encoding
branch
from
September 2, 2026 22:29
e48ee2a to
dab45a8
Compare
blaipr
force-pushed
the
fix/attachment-filename-encoding
branch
from
September 2, 2026 22:38
dab45a8 to
c9600c0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
downloadwrote attachment names raw into image links: an attachment calledmy file (1).pngbecame.png), which every standard Markdown renderer (CommonMark, GitHub, editor previews) reads as a link target ending at the first space — the image does not render. In the other direction, a link written the standard way by hand () was taken literally:ri:filename="my%20file.png"went into the page andattach_local_imageslooked for a file literally namedmy%20file.png, reported it missing, and left a broken attachment reference.Python-Markdown happens to accept spaces inside link targets, so the tool's own round trip masked both problems.
Change
quote()d in the link target (my%20file%20%281%29.png); the alt text is unchanged.srcisunquote()d before it is used as the attachment filename and collected forattach_local_images.download_pagedecodes the names it extracts from the links before matching them against the page's attachments and writing them to disk.Compatibility
Links without spaces or special characters are unchanged in both directions. Markdown files downloaded before this change (raw spaces) still upload correctly, since
unquote()leaves them alone.Checklist
ruff check src tests,ruff format --check src testsandpython -m pytest tests/passtests/test_images.py)docs/conversion.md, Images)docs/conversion.mdupdated because an equivalence changedCHANGELOG.mdupdated under Unreleased