fix(nitro): handle decoding static filenames (#3541)

This commit is contained in:
Daniel Roe 2022-03-08 17:30:46 +00:00 committed by GitHub
parent 5b7fbc1569
commit 91256f5e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -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(),

View File

@ -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
}
}