Skip to content

Commit ad321f8

Browse files
fix(cloudflare): allow spaces in filenames (sveltejs#3047)
* Added URL decode to Cloudflare adapter static logic. * Added changeset. * Updated to attempt URL decode and ignore on fail. Co-authored-by: Luke Edwards <[email protected]> * Fixed formatting issues. Co-authored-by: Luke Edwards <[email protected]>
1 parent 5f4d078 commit ad321f8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/twenty-turkeys-promise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-cloudflare': patch
3+
---
4+
5+
Updated Cloudflare adapter to allow static files with spaces (eg. "Example File.pdf") to be accessed.

packages/adapter-cloudflare/files/worker.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ init();
66
export default {
77
async fetch(req, env) {
88
const url = new URL(req.url);
9+
910
// check generated asset_set for static files
10-
if (ASSETS.has(url.pathname.substring(1))) {
11+
let pathname = url.pathname.substring(1);
12+
try {
13+
pathname = decodeURIComponent(pathname);
14+
} catch (err) {
15+
// ignore
16+
}
17+
18+
if (ASSETS.has(pathname)) {
1119
return env.ASSETS.fetch(req);
1220
}
1321

0 commit comments

Comments
 (0)