Skip to content

fix(docx-export): embed data-URI images instead of leaking base64 text - #389

Merged
petertzy merged 3 commits into
petertzy:mainfrom
harsh-thakkar7:fix/docx-data-uri-images
Oct 8, 2026
Merged

petertzy merged 3 commits into
petertzy:mainfrom
harsh-thakkar7:fix/docx-data-uri-images

Conversation

@harsh-thakkar7

Copy link
Copy Markdown
Contributor

_resolve_image_source handled file://, http(s), and relative paths, but not data: URIs. An inline image like ![pixel](data:image/png;base64,iVBORw0K...) fell through to the on-disk path candidates, returned (src, None), and the <img> handler wrote [data:image/png;base64,iVBORw0K...] as the paragraph's literal text — a raw base64 blob visible in the exported DOCX, with no embedded picture.

Fix: decode data: URIs in _resolve_image_source (base64 for ;base64 payloads, URL-unquote otherwise) and return the bytes so add_picture() embeds the image.

Adds test_data_uri_image_is_embedded_not_leaked_as_text, which failed on main (the blob appeared as paragraph text and inline_shapes was empty) and passes here (no data: text, one inline shape).

@petertzy

petertzy commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Approved — this fixes the DOCX export path for inline data-URI images by decoding the payload and passing image bytes to add_picture(), so Base64 content is embedded as an image instead of leaking into document text.
I also added compatibility coverage for case-insensitive data-URI metadata and URL-encoded image payloads. Backend tests (474 passed), frontend tests (94/94), Ruff, ESLint, and TypeScript checks all pass.

@petertzy
petertzy merged commit 8dc318f into petertzy:main Oct 8, 2026
2 checks passed
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