Skip to content

Commit

Permalink
fix(cloudflare): allow spaces in filenames (#3047)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
isaac-mcfadyen and lukeed authored Dec 21, 2021
1 parent 5f4d078 commit ad321f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/twenty-turkeys-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare': patch
---

Updated Cloudflare adapter to allow static files with spaces (eg. "Example File.pdf") to be accessed.
10 changes: 9 additions & 1 deletion packages/adapter-cloudflare/files/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ad321f8

Please sign in to comment.