Skip to content

fix: export wikis whose repository name is not ASCII - #626

Merged
sng-asyncfunc merged 2 commits into
AsyncFuncAI:mainfrom
lbarrosby:export-wiki-non-ascii-filename
Nov 8, 2026
Merged

sng-asyncfunc merged 2 commits into
AsyncFuncAI:mainfrom
lbarrosby:export-wiki-non-ascii-filename

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

POST /export/wiki builds the download name from the last part of repo_url and sends it as Content-Disposition: attachment; filename={filename}. Starlette encodes header values as latin-1, so when the name is not latin-1 the response cannot be built and the export fails with a 500 (UnicodeEncodeError). This happens, for example, with a local repository in /home/user/项目. A name with a space (/home/user/my repo) went out unquoted.

Fix

  • api/routers/wiki.py: a small _attachment_header helper sends a quoted ASCII fallback in filename= (anything outside [A-Za-z0-9._-] becomes _) and the real name percent-encoded in filename*=UTF-8''... (RFC 6266). Browsers and the repo page use filename*.
  • src/app/[owner]/[repo]/page.tsx: the export handler used /filename=(.+)/ and would have taken everything after the first filename=. It now reads filename* first (with decodeURIComponent), falls back to the quoted filename= and then to the existing default.

ASCII names download with the same file name as before.

Tests

New tests/backend/routers/test_wiki_export.py posts an export for a GitHub URL, /home/user/项目 and /home/user/my repo. It checks that the header is pure ASCII, has a quoted filename=, and that filename* decodes to <name>_wiki_<timestamp>.md.

  • on main: 3 failed (500 for the non-ASCII name, unquoted filename= without filename* for the others)
  • with the change: 3 passed; pytest tests/test_config.py tests/backend: 63 passed
  • tsc --noEmit -p . passes. next lint currently fails on main itself (FlatCompat import in the ESLint config), so I could not run it.

/export/wiki put the repository name straight into
Content-Disposition. Header values are encoded as latin-1, so a local
repository in a directory such as /home/user/项目 made the export fail
with a 500 (UnicodeEncodeError), and a name with a space produced an
unquoted filename. Send a quoted ASCII fallback in filename= and the
real name in filename*=UTF-8'' (RFC 6266), and have the repo page read
filename* first.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>

@sashimikun sashimikun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found in a brief review. Small test improvement: add frontend coverage for filename* taking precedence, malformed percent-encoding falling back to filename=, and a missing header keeping the default name. The new backend tests don't exercise that download-name parsing path.

Move the Content-Disposition parsing out of the export handler into
src/utils/contentDisposition.ts and test it with node:test (no new
dependencies): filename* precedence, malformed percent-encoding
falling back to filename=, and a missing header keeping the default.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@lbarrosby

Copy link
Copy Markdown
Contributor Author

Good point, the backend tests never touched that path. I moved the header parsing into src/utils/contentDisposition.ts and added tests for filename* winning, malformed percent-encoding falling back to filename=, and a missing header keeping the default name. There was no frontend test runner, so they use node:test with no new dependencies: npm test (needs Node 22.18+ to load the .ts file directly).

@sng-asyncfunc
sng-asyncfunc merged commit 6ec6712 into AsyncFuncAI:main Nov 8, 2026
3 checks passed
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.

3 participants