diff --git a/CHANGELOG.md b/CHANGELOG.md index b928bcf4..f7b146c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Fixed "API preview" examples ([#7782](https://github.com/pocketbase/pocketbase/issues/7782)). +- Added quotes around the default `Content-Disposition` serving filename in case custom name with special characters is provided. + ## v0.39.10 diff --git a/tools/filesystem/filesystem.go b/tools/filesystem/filesystem.go index 319ed8c4..50b602f9 100644 --- a/tools/filesystem/filesystem.go +++ b/tools/filesystem/filesystem.go @@ -464,7 +464,7 @@ func (s *System) Serve(res http.ResponseWriter, req *http.Request, fileKey strin extContentType = ct } - setHeaderIfMissing(res, "Content-Disposition", disposition+"; filename="+name) + setHeaderIfMissing(res, "Content-Disposition", disposition+"; filename="+strconv.Quote(name)) setHeaderIfMissing(res, "Content-Type", extContentType) setHeaderIfMissing(res, "Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'unsafe-inline'; sandbox") diff --git a/tools/filesystem/filesystem_test.go b/tools/filesystem/filesystem_test.go index f3b4d540..f3e20634 100644 --- a/tools/filesystem/filesystem_test.go +++ b/tools/filesystem/filesystem_test.go @@ -365,7 +365,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.txt", + "Content-Disposition": `attachment; filename="test_name.txt"`, "Content-Type": "application/octet-stream", "Content-Length": "4", "Content-Security-Policy": csp, @@ -380,7 +380,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "inline; filename=test_name.png", + "Content-Disposition": `inline; filename="test_name.png"`, "Content-Type": "image/png", "Content-Length": "73", "Content-Security-Policy": csp, @@ -395,7 +395,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name_download.png", + "Content-Disposition": `attachment; filename="test_name_download.png"`, "Content-Type": "image/png", "Content-Length": "73", "Content-Security-Policy": csp, @@ -410,7 +410,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.abc", + "Content-Disposition": `attachment; filename="test_name.abc"`, "Content-Type": "image/svg+xml", "Content-Length": "0", "Content-Security-Policy": csp, @@ -425,7 +425,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name", + "Content-Disposition": `attachment; filename="test_name"`, "Content-Type": "text/css", "Content-Length": "0", "Content-Security-Policy": csp, @@ -440,7 +440,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.abc", + "Content-Disposition": `attachment; filename="test_name.abc"`, "Content-Type": "text/javascript", "Content-Length": "0", "Content-Security-Policy": csp, @@ -455,7 +455,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.abc", + "Content-Disposition": `attachment; filename="test_name.abc"`, "Content-Type": "text/javascript", "Content-Length": "0", "Content-Security-Policy": csp, @@ -470,7 +470,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.abc", + "Content-Disposition": `attachment; filename="test_name.abc"`, "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Content-Length": "0", "Content-Security-Policy": csp, @@ -485,7 +485,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.abc", + "Content-Disposition": `attachment; filename="test_name.abc"`, "Content-Type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Content-Length": "0", "Content-Security-Policy": csp, @@ -500,7 +500,7 @@ func TestFileSystemServe(t *testing.T) { nil, false, map[string]string{ - "Content-Disposition": "attachment; filename=test_name.abc", + "Content-Disposition": `attachment; filename="test_name.abc"`, "Content-Type": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "Content-Length": "0", "Content-Security-Policy": csp,