Skip to content

demos: a file the agent made previews and downloads whatever it is called - #51

Merged
richard-epsilla merged 1 commit into
mainfrom
fix/demo-download-any-filename
Oct 30, 2026
Merged

richard-epsilla merged 1 commit into
mainfrom
fix/demo-download-any-filename

Conversation

@richard-epsilla

Copy link
Copy Markdown
Contributor

What was wrong

The preview and download routes in both demos (01-cursor-coding-app, 02-lumacare) put the file's raw name into Content-Disposition: ...; filename="<name>". A header value is bytes, so Node's res.setHeader throws ERR_INVALID_CHAR on any character above U+00FF. A file the agent named 报告.md or 🚀 launch.png answered 500 on both routes.

The fix

Each demo gets server/disposition.ts, the same Content-Disposition the HarnessRouter gateway sends:

  • an ASCII stand-in every client can read (non-ASCII and control characters become _, and " and \ are dropped)
  • RFC 6266 filename*=UTF-8''<percent-encoded name>, which every current browser prefers

A line break can never reach the header.

Checks

  • tests/disposition.test.ts in each demo runs 9 names through node:http's validateHeaderValue (the check setHeader makes), for both inline and attachment. It also pins that the old header is the one Node refuses. The counts are 16 and 21 tests, the existing ones plus 10 new in each demo.
  • The CI steps in Node 22 (npm ci, npm test, npm run build, npm audit --omit=dev --audit-level=high) all pass.
  • On a real Express server (each demo's own express), with a client reading status and header:
name old route new route
notes.txt 200 200, real name notes.txt
报告.md 500 ERR_INVALID_CHAR 200, real name 报告.md
🚀 launch.png 500 ERR_INVALID_CHAR 200, real name 🚀 launch.png
café (1).md 200 200, real name café (1).md
say "hi".txt 200 200, real name say "hi".txt

The kits are unaffected, because none of them writes this header.

🤖 Generated with Claude Code

…lled

The two demos' preview and download routes put the file's raw name into `filename="..."`, and a
header value is bytes: Node's setHeader throws ERR_INVALID_CHAR on 报告.md or an emoji, so both
routes answered 500 for exactly the files a non-English agent writes. Each demo gets
server/disposition.ts, the same Content-Disposition the HarnessRouter gateway sends: an ASCII
stand-in every client can read plus RFC 6266 filename* with the real name, which every current
browser prefers. Control characters never reach the header.

tests/disposition.test.ts runs 9 names through node:http's validateHeaderValue (the check setHeader
makes) for inline and attachment, and pins that the old header is the one Node refuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@richard-epsilla
richard-epsilla merged commit 442357f into main Oct 30, 2026
10 checks passed
@richard-epsilla
richard-epsilla deleted the fix/demo-download-any-filename branch October 30, 2026 11:27
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.

1 participant