From ad321f8d7dadf3f5b874d5aa434776a968e1bc8b Mon Sep 17 00:00:00 2001 From: Isaac McFadyen <6243993+mcfadyeni@users.noreply.github.com> Date: Tue, 21 Dec 2021 17:51:49 -0500 Subject: [PATCH] fix(cloudflare): allow spaces in filenames (#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 * Fixed formatting issues. Co-authored-by: Luke Edwards --- .changeset/twenty-turkeys-promise.md | 5 +++++ packages/adapter-cloudflare/files/worker.js | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/twenty-turkeys-promise.md diff --git a/.changeset/twenty-turkeys-promise.md b/.changeset/twenty-turkeys-promise.md new file mode 100644 index 000000000000..a9ce146bf740 --- /dev/null +++ b/.changeset/twenty-turkeys-promise.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-cloudflare': patch +--- + +Updated Cloudflare adapter to allow static files with spaces (eg. "Example File.pdf") to be accessed. diff --git a/packages/adapter-cloudflare/files/worker.js b/packages/adapter-cloudflare/files/worker.js index 8378d9f5add7..df9fea234039 100644 --- a/packages/adapter-cloudflare/files/worker.js +++ b/packages/adapter-cloudflare/files/worker.js @@ -6,8 +6,16 @@ init(); export default { async fetch(req, env) { const url = new URL(req.url); + // check generated asset_set for static files - if (ASSETS.has(url.pathname.substring(1))) { + let pathname = url.pathname.substring(1); + try { + pathname = decodeURIComponent(pathname); + } catch (err) { + // ignore + } + + if (ASSETS.has(pathname)) { return env.ASSETS.fetch(req); }