fix: image src not rewritten in markdown when page title contains an apostrophe - #16
Merged
takeoverjp merged 2 commits intoJul 2, 2026
Conversation
takeoverjp
commented
Jul 2, 2026
Contributor
- fix: local assets not recognized when page title contains an apostrophe (Bug: image src not rewritten in Markdown when page title contains an apostrophe #15)
- fix: correctly rewrite img src when URL contains an apostrophe (Bug: image src not rewritten in Markdown when page title contains an apostrophe #15)
…he (#15) ## Problem When a Confluence page title contained an apostrophe (`'`), draw.io and regular image assets were not recognized as local files and the tool attempted to re-download them as remote URLs, resulting in a warning and a failed fetch: WARN Failed to fetch image: https://example.com/confluence2md's_…_assets%2Fsingle.drawio.png ## Root cause `to_markdown_asset_path` (utils.rs) encodes asset paths using the `URI_COMPONENT` character set, which leaves `'` as a literal character. `is_local_markdown_asset` (confluence.rs) built its comparison prefix using the `PATH_SEGMENT` character set, which encodes `'` as `%27`. The resulting mismatch caused the prefix check to fail for any page title containing an apostrophe, so every asset on such a page was treated as a remote URL. // old: PATH_SEGMENT encodes ' → %27 encoded_prefix = "confluence2md%27s_…_assets" // src produced by to_markdown_asset_path (URI_COMPONENT, ' is literal) src = "confluence2md's_…_assets%2Fsingle.drawio.png" // starts_with check → false → asset downloaded as remote URL ## Fix Change `is_local_markdown_asset` to encode the comparison prefix with `URI_COMPONENT` instead of `PATH_SEGMENT`, matching the encoding used by `to_markdown_asset_path`. Export `URI_COMPONENT` as `pub` from utils.rs and import it in confluence.rs. ## Tests Added regression tests in `confluence::tests`: - `is_local_markdown_asset_recognizes_apostrophe_in_prefix` — verifies that a path generated by `to_markdown_asset_path` with an apostrophe in the prefix is recognized as a local asset (would fail with the old `PATH_SEGMENT`-based code) - `is_local_markdown_asset_recognizes_plain_prefix` — ensures the ordinary case continues to work - `is_local_markdown_asset_rejects_remote_url` — ensures remote URLs are not mistakenly treated as local assets
When a Confluence page title contains an apostrophe (e.g. "My team's page"), the Confluence REST API renders image `src` attributes using single-quoted HTML attribute values (e.g. `src='…/My%20team%27s%20page/image.png'`). The previous regex used a back-reference approach (`["']` open + `["']` close) that verified the opening and closing quotes matched. However, if the captured src string itself contained a single-quote character the regex engine would stop the lazy `.*?` match early—at the embedded quote—causing the closing-quote group to see a mismatch and skip the rewrite entirely. As a result the local asset path was never substituted and the generated Markdown still pointed at the remote Confluence URL. Fix: rewrite the regex to use two independent alternating groups (`"([^"]*)"` and `'([^']*)'`) so each branch only matches content that cannot contain its own delimiter. The replacement logic picks the correct quote character from whichever group matched, making the rewrite robust regardless of which delimiter Confluence chose for the attribute. Also adds a regression test that mocks a Confluence image endpoint whose path contains a percent-encoded apostrophe and asserts the resulting HTML has the src rewritten to a local asset path.
takeoverjp
deleted the
15-bug-image-src-not-rewritten-in-markdown-when-page-title-contains-an-apostrophe
branch
July 2, 2026 15:55
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.