From 39e72a5743cfb9d10882915e53c8ffd3ab4c03fa Mon Sep 17 00:00:00 2001 From: liuyuanchuang Date: Fri, 13 Mar 2026 17:41:18 +0800 Subject: [PATCH] fix: encode non-ASCII filename in Content-Disposition header Use RFC 5987 filename*=UTF-8'' percent-encoding to support Chinese and other Unicode characters in DOCX download filenames. Co-Authored-By: Claude Sonnet 4.6 --- app/api/v1/endpoints/convert.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/api/v1/endpoints/convert.py b/app/api/v1/endpoints/convert.py index c2f8783..76482e7 100644 --- a/app/api/v1/endpoints/convert.py +++ b/app/api/v1/endpoints/convert.py @@ -1,5 +1,7 @@ """Format conversion endpoints.""" +from urllib.parse import quote + from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import Response @@ -34,10 +36,11 @@ async def convert_markdown_to_docx( request.filename, len(docx_bytes), ) + encoded_name = quote(f"{request.filename}.docx") return Response( content=docx_bytes, media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document", - headers={"Content-Disposition": f'attachment; filename="{request.filename}.docx"'}, + headers={"Content-Disposition": f"attachment; filename*=UTF-8''{encoded_name}"}, ) except Exception as e: logger.exception("DOCX conversion failed, filename=%s: %s", request.filename, e)