GeezerVison is showing github.com — 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') · Issue #1494 · developing-today/code
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') #1494Labels app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator job Descriptionid(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
%XX sequence 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 throws URIError before saveFile's try block, and AutoSaveManager.triggerSave has no try/catch either — the manager is left in state "saving" forever and saveNow() 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}", where doc_id_escaped = html_escape(doc_id) (templates.rs:418) and name_urlencoded = urlencoding::encode(name) (templates.rs:421). The editor caller passes the raw file name as doc_id (pkgs/id/src/web/routes.rs, file_by_name_handler: render_editor(&name, &name, &content, &hash)), so dataset.docId in the browser is the raw name, not a percent-encoded string.
-
openEditor does it correctly — main.ts:1195-1196 reads dataset.filename and decodes it. The tag panel (:1004, :1044), download (:1410-1411), rename (:1459-1460) and copy (:1530-1531) paths all read dataset.filename too. Only saveFile differs: main.ts:1305-1306
const filenameEncoded = editorContainer.dataset.docId;
const filename = filenameEncoded ? decodeURIComponent(filenameEncoded) : null;
-
The throw escapes both layers: in saveFile the decode at :1306 runs before the try at :1318; AutoSaveManager.triggerSave (main.ts:121-127) is const result = await this.saveFn(); with no try/catch; saveNow (:89-100, guard at :96) returns early when state === "saving". The fallback path in triggerSave() (:1592-1611) attaches only .then(...) to saveFile(), so it also produces an unhandled rejection.
-
The server trusts the posted name completely: save_handler (routes.rs:1195+) detects the content mode from req.name, publishes with a filename tag of req.name, archives under req.name, and sets the tag req.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.md and saving writes the content to the tag a b.md — overwriting a different real file if one exists — while a%20b.md itself keeps its old content. The decoded name also drives convert_doc_to_bytes mode detection on the server, so a name like notes%2Etxt-style decodings can even change how the document is converted.
- Total save failure with a wedged UI. For
100%.md, 50%off.md and 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
saveFile posts the document's actual filename for names containing %: a%20b.md saves as a%20b.md (not a b.md), %41.md as %41.md, caf%C3%A9.md as caf%C3%A9.md. (Reading dataset.filename like every other consumer, or dropping the decode for dataset.docId, both satisfy this — the fix should match the server's actual encoding contract for whichever field it reads.)
- Saving
100%.md / 50%off.md succeeds: no URIError, a normal /api/save POST with the raw name, and the AutoSaveManager returns to saved/idle.
- Defense in depth: a
saveFn that throws or rejects cannot leave AutoSaveManager in state === "saving" — triggerSave settles into an error/unsaved state and a later saveNow() can retry.
- Regression tests (web unit tests, e.g. alongside the existing
main.ts-adjacent suites or an extracted helper) cover at least: a %XX name, a bare-% name, and a throwing saveFn leaving the manager retryable. Existing plain-name saves (notes.md, a b.md, résumé.md) are unchanged.
Related
Activitydeveloping-today commented on Oct 27, 2026 added kind/bugSomething isn't working (prefixed form of the classic bug label) task/triageQueue packet kind: verify, reproduce, and route this item app/idPackage/app: id (pkgs/ or apps/ in this repo) effort/sSmall: expected under 2 hours of work on Oct 27, 2026dezren39 commented on Oct 27, 2026 🤖 Agent note · filed
- Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
- Session / ID: cron new-issue-creator-code-b, run 2026-10-27 13:28 CDT
- Found via: filed this run
- Task: Triage the saveFile dataset.docId decode defect: %-filenames save under a decoded wrong name (cross-file overwrite via save_handler's trusted req.name), and bare-% names throw URIError before saveFile's try block, wedging AutoSaveManager in "saving" with saveNow early-returning. Verified on main a1321fd with a Bun + happy-dom probe on the laptop (verbatim main.ts:1305-1306 expression over the exact templates.rs attribute string; dataset.filename path as control — all controls pass).
- Expectation: effort/s — fix the field/decode mismatch (match the server's encoding contract, as every other consumer does), make a throwing saveFn settle the AutoSaveManager into a retryable state, add regression tests for %XX names, bare-% names, and the throwing-saveFn case.
- Links: queue packet packet-1494.json (repo-health-code-pilot, triage)
dezren39 commented on Nov 1, 2026 🤖 Agent note · done — fixed & merged (task 4774)
- Agent: repo-worker-code (lane B)
- Session / ID: repo-queue-worker-shift-b 2026-10-31 · task 4774
- Result: PR fix(id/web): saveFile reads dataset.filename, not decoded docId (#1494) #3269 merged @ed3a285e68f017cdd9af815e596c21eb4ad50426 — saveFile resolves the save name from
dataset.filename via the new resolveSaveFilename helper (unit-tested: a%20b.md and 100%.md save 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"). The id CI 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.
MetadataMetadataapp/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator job DevelopmentNo branches or pull requestsIssue actions
|