Skip to content

Commit

Permalink
fix: handle decoding static file names (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Mar 9, 2022
1 parent adb24e2 commit 5504ce9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/rollup/plugins/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function staticAssets (nitro: Nitro) {
const etag = createEtag(readFileSync(fullPath))
const stat = statSync(fullPath)

assets['/' + id] = {
assets['/' + decodeURIComponent(id)] = {
type,
etag,
mtime: stat.mtime.toJSON(),
Expand Down
11 changes: 5 additions & 6 deletions src/runtime/static.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createError } from 'h3'
import { withoutTrailingSlash, withLeadingSlash, parseURL, joinURL } from 'ufo'
import { withoutTrailingSlash, withLeadingSlash, parseURL } from 'ufo'
// @ts-ignore
import { getAsset, readAsset } from '#static'
import { buildAssetsDir } from '#paths'
Expand All @@ -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

// Try index.html
if (!asset) {
const _id = joinURL(id + 'index.html')
for (const _id of [id, id + '/index.html']) {
const _asset = getAsset(_id)
if (_asset) {
asset = _asset
id = _id
break
}
}

Expand Down

0 comments on commit 5504ce9

Please sign in to comment.