Skip to content

Commit

Permalink
fix(dev): decode url before sirv resolve (#1432)
Browse files Browse the repository at this point in the history
fix #1426
  • Loading branch information
underfin committed Jan 8, 2021
1 parent 7a55c5b commit 7cc3cf1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vite/src/node/server/middlewares/static.ts
Expand Up @@ -14,7 +14,7 @@ export function serveStaticMiddleware(
const serve = sirv(dir, sirvOptions)

return (req, res, next) => {
const url = req.url!
let url = req.url!

// skip import request
if (isImportRequest(url)) {
Expand All @@ -30,6 +30,9 @@ export function serveStaticMiddleware(
) {
return next()
}

// #1426
url = req.url = decodeURIComponent(url)

// apply aliases to static requests as well
if (config) {
Expand Down Expand Up @@ -67,7 +70,7 @@ export function rawFsStaticMiddleware(): Connect.NextHandleFunction {
// the paths are rewritten to `/@fs/` prefixed paths and must be served by
// searching based from fs root.
if (url.startsWith(FS_PREFIX)) {
req.url = url.slice(FS_PREFIX.length)
req.url = decodeURIComponent(url.slice(FS_PREFIX.length))
serveFromRoot(req, res, next)
} else {
next()
Expand Down

0 comments on commit 7cc3cf1

Please sign in to comment.