From 91256f5e76a9d7b3a1e744324574f186b8b98a8b Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 8 Mar 2022 17:30:46 +0000 Subject: [PATCH] fix(nitro): handle decoding static filenames (#3541) --- packages/nitro/src/rollup/plugins/static.ts | 2 +- packages/nitro/src/runtime/server/static.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/nitro/src/rollup/plugins/static.ts b/packages/nitro/src/rollup/plugins/static.ts index 5aed86b190..ca26713f93 100644 --- a/packages/nitro/src/rollup/plugins/static.ts +++ b/packages/nitro/src/rollup/plugins/static.ts @@ -19,7 +19,7 @@ export function staticAssets (context: NitroContext) { const etag = createEtag(readFileSync(fullPath)) const stat = statSync(fullPath) - assets['/' + id] = { + assets['/' + decodeURIComponent(id)] = { type, etag, mtime: stat.mtime.toJSON(), diff --git a/packages/nitro/src/runtime/server/static.ts b/packages/nitro/src/runtime/server/static.ts index f29cfa4bd8..9bb78876dc 100644 --- a/packages/nitro/src/runtime/server/static.ts +++ b/packages/nitro/src/runtime/server/static.ts @@ -14,16 +14,15 @@ export default async function serveStatic (req, res) { return } - let id = withLeadingSlash(withoutTrailingSlash(parseURL(req.url).pathname)) - let asset = getAsset(id) + let id = decodeURIComponent(withLeadingSlash(withoutTrailingSlash(parseURL(req.url).pathname))) + let asset: string - // Try index.html - if (!asset) { - const _id = id + '/index.html' + for (const _id of [id, id + '/index.html']) { const _asset = getAsset(_id) if (_asset) { asset = _asset id = _id + break } }