From a4b7efb1c9bb0d04956f7487a7c66a227a547c7f Mon Sep 17 00:00:00 2001 From: lintsinghua Date: Wed, 10 Dec 2025 17:43:56 +0800 Subject: [PATCH] fix(rules): fix unicode encoding error in rule set export filename Use RFC 5987 filename*=UTF-8'' format for Content-Disposition header to support Chinese characters in exported filename --- backend/app/api/v1/endpoints/rules.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/api/v1/endpoints/rules.py b/backend/app/api/v1/endpoints/rules.py index b19ecd4..d59db6d 100644 --- a/backend/app/api/v1/endpoints/rules.py +++ b/backend/app/api/v1/endpoints/rules.py @@ -444,10 +444,14 @@ async def export_rule_set( "export_version": "1.0", } + # 使用 URL 编码处理中文文件名 + from urllib.parse import quote + encoded_filename = quote(f"{rule_set.name}.json") + return JSONResponse( content=export_data, headers={ - "Content-Disposition": f'attachment; filename="{rule_set.name}.json"' + "Content-Disposition": f"attachment; filename*=UTF-8''{encoded_filename}" } )