{{ message }}
Repository navigation
fix: preserve Windows drive image paths in export (#3323) - #5732
Merged
Merged
Conversation
Contributor
2 of 6 tasks
Tkaixiang
approved these changes
Oct 15, 2026
Tkaixiang
left a comment
Member
There was a problem hiding this comment.
lgtm, tested before and after results, after works well
…on (#3323) Replace the export URI allowlist change with the approach MarkText 0.17 used: rewrite Windows drive image paths to file:/// URLs before DOMPurify runs, so the sanitizer validates the final src instead of being widened to accept bare `C:` values. - add a `correctImageTokenSrc` marked walkTokens hook that runs image tokens through the existing `correctImageSrc` (#1997) helper - register it in `getHighlightHtml` (HTML / PDF / print export, `renderToStaticHTML`) and `getClipboardHtml` (copy as HTML); the shared `walkTokens` is left alone because the editor's lexer also uses it - revert both `ALLOWED_URI_REGEXP` edits and the allowlist specs - new `windowsDriveImageExport.spec.ts` drives all three renderers with `isWin` mocked Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tkaixiang
approved these changes
Oct 15, 2026
Member
There was a problem hiding this comment.
I decided to restore the original export behaviour present in 0.17
Previously, Windows drive letters C:\... were converted to file:/// before being passed into DOMPurify, so it was correctly parsed into src tags in images.
However, 0.20's Muya re-write caused this regression efcaf0c
…hem (#3323) Follow-up to the previous commit. Instead of rewriting only Markdown image tokens, resolve every exported <img> src while sanitizing, so the allowlist checks the final file:// URL and the desktop no longer patches srcs into already-sanitized HTML. - add `resolveExportImageSrc` (ported from the desktop `resolveLocalImageSrc`) to a new `utils/fileUrl.ts`, alongside the path helpers moved out of `utils/image.ts`; it leaves anything with a URL scheme to the sanitizer - add `sanitizeExportHtml`, which attaches an `uponSanitizeAttribute` hook to the shared purifier for the call only; use it in `MarkdownToHtml`, `renderToStaticHTML` and `getSanitizeClipboardHtml`. This also covers raw <img> tags, which the token hook missed (resized / aligned images) - drop the `correctImageTokenSrc` token hook - desktop: remove `rewriteImageSrcs`, the printService image loop and `resolveImageSrc.ts`; `renderMarkdown` loses its `renderStatic` flag - specs: `exportImageSrc.spec.ts` covers all three renderers and the ported resolver cases; desktop export specs add drive-path and raw <img> cases Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy as HTML puts the sanitized markup on the clipboard as text for pasting into other sites, where a resolved `file://` path is useless and exposes the user's folder layout. Revert `getSanitizeClipboardHtml` to the plain export sanitizer so only HTML / PDF / print export and `renderToStaticHTML` resolve image srcs, and pin the clipboard behaviour in `exportImageSrc.spec.ts`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Closes #3323
Summary
Exporting Markdown such as
loses the image source: the export sanitizer interprets the drive letter as an unsupported URL scheme and removessrcbefore the local-image resolver runs.Extend the Muya and desktop export sanitizers' existing URI allowlists to retain absolute Windows drive paths (
C:\...,C:/..., andC:%5C...). The existingresolveLocalImageSrcthen converts them tofile:///C:/...URLs in the shared HTML/PDF/print pipeline. Markdown rendering keeps its existing behavior, avoiding duplicate path conversion there. Source Markdown is unchanged.PR #5716 already repairs encoded separators downstream. This change ensures the absolute image source survives sanitization and reaches that resolver.
Type of change
Test plan
c:photo.png). A complete export-pipeline test verifies a JavaScript image source is removed.Notes for reviewers
The URI exception requires a single drive letter followed by a colon and a path separator; arbitrary unknown protocols remain blocked. As with the existing
ALLOWED_URI_REGEXP, the exception applies to all URI attributes inspected by the export sanitizer, includinghrefandsrc. It does not affect the preview sanitizer or enableALLOW_UNKNOWN_PROTOCOLS.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.