From 60328376d814eb5310f00231fb5e329d473e0004 Mon Sep 17 00:00:00 2001 From: Isaac McFadyen <6243993+mcfadyeni@users.noreply.github.com> Date: Tue, 14 Dec 2021 14:13:17 -0700 Subject: [PATCH 1/4] Added URL decode to Cloudflare adapter static logic. --- packages/adapter-cloudflare/files/worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/files/worker.js b/packages/adapter-cloudflare/files/worker.js index 8378d9f5add7..688481272112 100644 --- a/packages/adapter-cloudflare/files/worker.js +++ b/packages/adapter-cloudflare/files/worker.js @@ -7,7 +7,7 @@ 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))) { + if (ASSETS.has(decodeURIComponent(url.pathname.substring(1)))) { return env.ASSETS.fetch(req); } From c46e697ae69f373b2fdc6dfc4e5a7ad983706c44 Mon Sep 17 00:00:00 2001 From: Isaac McFadyen <6243993+mcfadyeni@users.noreply.github.com> Date: Tue, 14 Dec 2021 14:22:39 -0700 Subject: [PATCH 2/4] Added changeset. --- .changeset/twenty-turkeys-promise.md | 5 +++++ 1 file changed, 5 insertions(+) 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. From 71a688ccadd979d45e30bc9a5f162e3f498fefc0 Mon Sep 17 00:00:00 2001 From: Isaac McFadyen <6243993+mcfadyeni@users.noreply.github.com> Date: Mon, 20 Dec 2021 16:54:06 -0500 Subject: [PATCH 3/4] Updated to attempt URL decode and ignore on fail. Co-authored-by: Luke Edwards --- packages/adapter-cloudflare/files/worker.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/files/worker.js b/packages/adapter-cloudflare/files/worker.js index 688481272112..668fe053ace4 100644 --- a/packages/adapter-cloudflare/files/worker.js +++ b/packages/adapter-cloudflare/files/worker.js @@ -7,7 +7,14 @@ export default { async fetch(req, env) { const url = new URL(req.url); // check generated asset_set for static files - if (ASSETS.has(decodeURIComponent(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); } From 64c1047f7e08cd080de3e507aa5c9f31b68f7de6 Mon Sep 17 00:00:00 2001 From: Isaac McFadyen <6243993+mcfadyeni@users.noreply.github.com> Date: Tue, 21 Dec 2021 16:28:42 -0500 Subject: [PATCH 4/4] Fixed formatting issues. --- packages/adapter-cloudflare/files/worker.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/adapter-cloudflare/files/worker.js b/packages/adapter-cloudflare/files/worker.js index 668fe053ace4..df9fea234039 100644 --- a/packages/adapter-cloudflare/files/worker.js +++ b/packages/adapter-cloudflare/files/worker.js @@ -6,14 +6,15 @@ init(); export default { async fetch(req, env) { const url = new URL(req.url); + // check generated asset_set for static files - let pathname = url.pathname.substring(1); - try { - pathname = decodeURIComponent(pathname); - } catch (err) { - // ignore - } - + let pathname = url.pathname.substring(1); + try { + pathname = decodeURIComponent(pathname); + } catch (err) { + // ignore + } + if (ASSETS.has(pathname)) { return env.ASSETS.fetch(req); }