Skip to content

fix: use relative path for attachment entries in export zip - #2339

Open
TowyTowy wants to merge 1 commit into
docmost:mainfrom
TowyTowy:fix/export-zip-leading-slash
Open

fix: use relative path for attachment entries in export zip#2339
TowyTowy wants to merge 1 commit into
docmost:mainfrom
TowyTowy:fix/export-zip-leading-slash

Conversation

@TowyTowy

Copy link
Copy Markdown

Problem

Fixes #1307. When exporting a space (or a page tree) with attachments, the generated ZIP is invalid: Windows Explorer (and other spec-strict tools) cannot extract it. Attachment entries are written with a leading slash — an absolute path — which violates the ZIP spec (APPNOTE.TXT §4.4.17).

There is a second, silent consequence: exported pages reference attachments with the relative files/... URL (via updateAttachmentUrlsToLocalPaths), but the archive stores them at the absolute /files/... entry — so even when extracted, the links don't resolve for root-level pages.

Fix

Write attachment entries with a relative files/... path. This makes the archive spec-compliant and aligns the entry path with the relative URLs already written into the documents, so links resolve after extraction. Nested pages are unaffected (JSZip already normalizes the slash inside subfolders); the bug is specific to root-level pages, which is the space-export case in the report.

Testing

Added export.service.spec.ts covering zipAttachments: it asserts entries use a relative path (no leading slash) and are placed relative to the page folder. Verified fail-before/pass-after by reverting the one-line change (the root-page test fails with an absolute /files/... entry before). Confirmed the leading-slash behavior directly against jszip@3.10.1; tsc --noEmit clean.

Notes / disclosure

  • The spec stubs the ESM-only @sindresorhus/slugify (unrelated to zipping) so the export service can be imported under the current jest config without any config change.
  • Supersedes the abandoned, never-merged Fix invalid zip #1327, taking a minimal one-line approach.
  • This change was prepared with AI assistance (Claude); reviewed and verified before submission.

Attachment files were written to the export archive with an absolute
"/files/..." entry path. A leading slash produces an absolute zip
entry, which violates the ZIP spec (APPNOTE 4.4.17) and is rejected by
tools such as Windows Explorer, leaving the archive unextractable. It
also mismatches the relative "files/..." URLs written into the exported
pages by updateAttachmentUrlsToLocalPaths, so attachment links break
after extraction.

Use a relative "files/..." path so the archive is spec-compliant and
the in-document links resolve.

Fixes docmost#1307

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jul 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

Invalid zip archives when exporting space with attachments

2 participants