Repository navigation
Description
id(web): saveFile decodes the wrong dataset field — files with % in their name save under a different name, or can never save at all (URIError wedges AutoSaveManager in "saving")
Summary
saveFile() in pkgs/id/web/src/main.ts is the one place that reads the editor's filename from dataset.docId — and then runs decodeURIComponent on it. But the server never URL-encodes data-doc-id: it is written with plain HTML escaping, while the sibling data-filename attribute is the one that carries the URL-encoded name. Every other consumer reads dataset.filename. So for any filename containing a %:
- a valid
%XXsequence is silently decoded — the save is posted under a different file's name, and the server obligingly sets that other tag to the new blob; - an invalid
%sequence throwsURIErrorbeforesaveFile'stryblock, andAutoSaveManager.triggerSavehas notry/catcheither — the manager is left in state"saving"forever andsaveNow()early-returns on that state, so the file can never be saved (autosave or manual) until reload.
Evidence
The chain, all on main a1321fd5:
-
Server emits the attributes at
pkgs/id/src/web/templates.rs:486-487:data-doc-id="{doc_id_escaped}" data-filename="{name_urlencoded}", wheredoc_id_escaped = html_escape(doc_id)(templates.rs:418) andname_urlencoded = urlencoding::encode(name)(templates.rs:421). The editor caller passes the raw file name asdoc_id(pkgs/id/src/web/routes.rs,file_by_name_handler:render_editor(&name, &name, &content, &hash)), sodataset.docIdin the browser is the raw name, not a percent-encoded string. -
openEditordoes it correctly —main.ts:1195-1196readsdataset.filenameand decodes it. The tag panel (:1004,:1044), download (:1410-1411), rename (:1459-1460) and copy (:1530-1531) paths all readdataset.filenametoo. OnlysaveFilediffers:main.ts:1305-1306const filenameEncoded = editorContainer.dataset.docId; const filename = filenameEncoded ? decodeURIComponent(filenameEncoded) : null;
-
The throw escapes both layers: in
saveFilethe decode at:1306runs before thetryat:1318;AutoSaveManager.triggerSave(main.ts:121-127) isconst result = await this.saveFn();with notry/catch;saveNow(:89-100, guard at:96) returns early whenstate === "saving". The fallback path intriggerSave()(:1592-1611) attaches only.then(...)tosaveFile(), so it also produces an unhandled rejection. -
The server trusts the posted name completely:
save_handler(routes.rs:1195+) detects the content mode fromreq.name, publishes with afilenametag ofreq.name, archives underreq.name, and sets the tagreq.name → new_hash. A decoded-wrong name is not an error — it is a cross-file overwrite.
Verified this run on main a1321fd5 with a Bun + happy-dom probe on the laptop (~/git/fleet/probe-2026-10-27-laneB-docid; main.ts sha256 43e3541e… identical on sandbox and laptop; probe + log in the goal's hidden_files/probe-2026-10-27-laneB-docid/). The probe rebuilds the exact attribute string templates.rs emits, parses it with a real DOM, and runs the verbatim main.ts:1305-1306 expression (with the main.ts:1195-1196 expression as control):
name="notes.md" dataset.docId="notes.md" saveFile: OK ("notes.md") | openEditor(dataset.filename): OK
name="a b.md" dataset.docId="a b.md" saveFile: OK ("a b.md") | openEditor(dataset.filename): OK
name="a%20b.md" dataset.docId="a%20b.md" saveFile: WRONG NAME -> save posts name="a b.md" | openEditor(dataset.filename): OK
name="%41.md" dataset.docId="%41.md" saveFile: WRONG NAME -> save posts name="A.md" | openEditor(dataset.filename): OK
name="caf%C3%A9.md" dataset.docId="caf%C3%A9.md" saveFile: WRONG NAME -> save posts name="café.md" | openEditor(dataset.filename): OK
name="100%.md" dataset.docId="100%.md" saveFile: THROWS URIError: URI error | openEditor(dataset.filename): OK
name="50%off.md" dataset.docId="50%off.md" saveFile: THROWS URIError: URI error | openEditor(dataset.filename): OK
name="résumé.md" dataset.docId="résumé.md" saveFile: OK ("résumé.md") | openEditor(dataset.filename): OK
autosave triggerSave REJECTED (URIError) — state stuck at "saving"
saveNow: early return (state === 'saving') — no save attempted | final state = saving
Why it matters
Two failure classes from one wrong field:
- Silent cross-file corruption. Editing
a%20b.mdand saving writes the content to the taga b.md— overwriting a different real file if one exists — whilea%20b.mditself keeps its old content. The decoded name also drivesconvert_doc_to_bytesmode detection on the server, so a name likenotes%2Etxt-style decodings can even change how the document is converted. - Total save failure with a wedged UI. For
100%.md,50%off.mdand any other bare-%name, every save attempt throws, the save button stays on "saving…" (disabled), and neither autosave nor Ctrl+S/button (both route through the stuck manager) can ever succeed. The user's edits are unsaveable without a reload — and a reload loses them.
Percent signs in filenames are unremarkable (exports, URL-ish names, 100%.md coverage notes), and the editor opens these files perfectly — only saving is broken, which is the worst place to discover it.
Acceptance criteria
saveFileposts the document's actual filename for names containing%:a%20b.mdsaves asa%20b.md(nota b.md),%41.mdas%41.md,caf%C3%A9.mdascaf%C3%A9.md. (Readingdataset.filenamelike every other consumer, or dropping the decode fordataset.docId, both satisfy this — the fix should match the server's actual encoding contract for whichever field it reads.)- Saving
100%.md/50%off.mdsucceeds: noURIError, a normal/api/savePOST with the raw name, and the AutoSaveManager returns tosaved/idle. - Defense in depth: a
saveFnthat throws or rejects cannot leaveAutoSaveManagerinstate === "saving"—triggerSavesettles into an error/unsaved state and a latersaveNow()can retry. - Regression tests (web unit tests, e.g. alongside the existing
main.ts-adjacent suites or an extracted helper) cover at least: a%XXname, a bare-%name, and a throwingsaveFnleaving the manager retryable. Existing plain-name saves (notes.md,a b.md,résumé.md) are unchanged.
Related
- id(web): header subtitle injects the raw document filename via innerHTML — a crafted filename becomes live markup (stored XSS) #1457 is the same dataset family but a different sink (the header subtitle's
innerHTML); this issue is the save path only. - id(web): AutoSaveManager runs concurrent saves and a stale completion marks newer edits saved #1440 is the AutoSaveManager concurrency defect (concurrent saves / stale completion); this issue is its exception path — a throwing save wedging the state machine. The two fixes touch nearby code and should be checked against each other when either lands.
Activity
developing-today commentedon Oct 27, 2026
CODE-560
dezren39 commentedon Oct 27, 2026
🤖 Agent note · filed
13 remaining items
Merge pull request #3269 from developing-today/queue/4774-1494-savefi…
dezren39 commentedon Nov 1, 2026
🤖 Agent note · done — fixed & merged (task 4774)
dataset.filenamevia the newresolveSaveFilenamehelper (unit-tested:a%20b.mdand100%.mdsave under their own exact names), and the triggerSave fallback gained a.catch. Verified on the laptop at head 81871e1: save-filename tests 6/6, full web suite passes except the search-panel failure proven identical on clean main (pre-existing), tsc clean for the touched files (only the pre-existing image-upload.test.ts error remains), Codex review clean ("didn't find any major issues"). TheidCI run sat queued in the runner backlog from 00:53Z; merged on laptop verification per the standing directive, with the queued run as the post-merge gate. Issue closed by the merge; in-flight labels removed.