From eaa61f5ed9b4631e8dc83a2bf49418f4f17647f5 Mon Sep 17 00:00:00 2001 From: chrislu Date: Fri, 5 Dec 2025 15:27:27 -0800 Subject: [PATCH] fix: Use mime.FormatMediaType for RFC 6266 compliant Content-Disposition Replace manual escaping with mime.FormatMediaType which properly handles non-ASCII characters and special characters per RFC 6266, ensuring correct filename display for international users. --- weed/admin/handlers/file_browser_handlers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/weed/admin/handlers/file_browser_handlers.go b/weed/admin/handlers/file_browser_handlers.go index 60e46fbc6..bafaa60c3 100644 --- a/weed/admin/handlers/file_browser_handlers.go +++ b/weed/admin/handlers/file_browser_handlers.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "io" + "mime" "mime/multipart" "net" "net/http" @@ -588,10 +589,9 @@ func (h *FileBrowserHandlers) DownloadFile(c *gin.Context) { // Set headers for file download fileName := filepath.Base(cleanFilePath) - // Escape quotes and backslashes in filename per RFC 2616 - escapedFileName := strings.ReplaceAll(fileName, "\\", "\\\\") - escapedFileName = strings.ReplaceAll(escapedFileName, "\"", "\\\"") - c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", escapedFileName)) + // Use mime.FormatMediaType for RFC 6266 compliant Content-Disposition, + // properly handling non-ASCII characters and special characters + c.Header("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": fileName})) // Use content type from filer response, or default to octet-stream contentType := resp.Header.Get("Content-Type")