Repository navigation
fix(collab): back-fill attachmentId from file URL on HTML→JSON writes (#392) - #36
Merged
Merged
Conversation
…docmost#392) Every attachment node type (image/video/audio/pdf/attachment/excalidraw/drawio) parses `attachmentId` only from a `data-attachment-id` attribute, so an agent authoring the natural `<img src="/api/files/<uuid>/x.png">` (or `<video>`/`<audio>`) over the /v1 API produced a node with `attachmentId: null` — it rendered (the view reads `src` alone) but the page↔attachment linkage was silently lost, orphaning the file to `getAttachmentIds` (export / share / duplicate all key on it). `htmlToJson` now back-fills `attachmentId` from the node's same-origin file URL (`attrs.src`, or `attrs.url` for the attachment node) after `generateJSON`, covering all attachment node types in one place. An explicit `data-attachment-id` still wins; the URL match is anchored to a leading slash (an external URL that merely contains `/api/files/<uuid>` never matches) and gated by the version-agnostic `isValidUUID` (Docmost mints uuidv7). The inherited `img[src]:not([src^="data:"])` tag gate is untouched, so inline `data:` images still drop. Covers the server /v1 + markdown-import path (what docmost#392 reports). Spec lives under src/editor-compat/ so the docmost-authz jest glob runs it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…tor-compat (review) Address the PR review (wiki-v2#396): the ~40 lines of new attachmentId-backfill logic lived inline in the upstream-owned collaboration.util.ts. Per the fork model (new logic in fork-owned/boundary-excluded dirs; upstream files get minimal wiring — mirrors the #59/#61 typography seam), extract the regex + attachmentIdFromFileUrl + backfillAttachmentIds into apps/server/src/editor-compat/attachment-id-backfill.ts, leaving collaboration.util.ts with just an import + the one call in htmlToJson. No behavior change; the editor-compat spec (which exercises the real htmlToJson path) stays green and now also pins that isValidUUID is load-bearing (a 36-char [0-9a-f-] non-UUID must not backfill). Documents the doubled-walk as an accepted tradeoff. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… seam (docmost#392) CI caught it: moving the docmost#392 backfill logic into fork-owned editor-compat/ (review) made the upstream-owned collaboration.util.ts import CCC code, which the fork import-boundary spec (rule 3) flags unless the seam is documented. Add collaboration/collaboration.util.ts to SEAM_ALLOWLIST (it now imports editor-compat/attachment-id-backfill), cross-referenced to UPSTREAM_MODIFICATIONS #61. Also satisfies the rule-3 hygiene check (the file genuinely imports CCC code now). Co-Authored-By: Claude Opus 4.8 <[email protected]>
PMQ9
force-pushed
the
fix/392-attachment-id-backfill
branch
from
September 18, 2026 14:42
c9070f2 to
5828dde
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.
What
htmlToJsonnow back-fills a node'sattachmentIdfrom its same-origin file URL when the HTML author omitteddata-attachment-id.Every attachment node type (
image/video/audio/pdf/attachment/excalidraw/drawio) parsesattachmentIdonly from adata-attachment-idattribute. So an agent authoring the natural<img src="/api/files/<uuid>/x.png">(or<video src>/<audio src>) over the/v1API produced a node withattachmentId: null— it renders (the view readssrcalone) but the page↔attachment linkage is silently lost, orphaning the file togetAttachmentIds, which export / share / duplicate all key on.A single
backfillAttachmentIdspost-pass inhtmlToJson(beside the existingaddUniqueIdsToDoc) recovers the id fromattrs.src(orattrs.urlfor the attachment node) for every attachment node type. An explicitdata-attachment-idstill wins; the URL match is anchored to a leading slash (an externalhttps://evil.example/api/files/<uuid>/…never matches) and gated by the version-agnosticisValidUUID(Docmost mints uuidv7, so a v4-only regex would silently no-op). The inheritedimg[src]:not([src^="data:"])tag gate is untouched — inlinedata:images still drop.Covers the server
/v1+ markdown-import path. This is the wiki-v2 super-repo's issue docmost#392; it pairs with a super-repo PR that adds awiki_upload_attachmentMCP tool (docmost#368) which authors correct JSON directly.Testing
apps/server/src/editor-compat/attachment-id-backfill.spec.tsexercises the realhtmlToJsonpath: image/video/audio backfill (Class A), the/files/,/public/, and?queryURL variants, explicit-id-wins, external-URL and anchored-slash-spoof rejection, non-UUID rejection, thedata:drop, and the attachment-node (Class B) safety net.Co-Authored-By: Claude Opus 4.8 [email protected]