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
This commit is contained in:
lintsinghua 2025-12-10 17:43:56 +08:00
parent 82b9733e92
commit a4b7efb1c9
1 changed files with 5 additions and 1 deletions

View File

@ -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}"
}
)