Skip to content

Commit

Permalink
refactor: encodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jul 8, 2022
1 parent c59a76a commit 5cc05bf
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,13 @@ export function serveStaticMiddleware(
}

if (redirected) {
req.url = encodePercent(redirected)
req.url = encodeURIComponent(redirected)
}

serve(req, res, next)
}
}

const percentRe = /%/g
function encodePercent(url: string) {
return url.includes('%') ? url.replace(percentRe, '%25') : url
}

export function serveRawFsMiddleware(
server: ViteDevServer
): Connect.NextHandleFunction {
Expand Down Expand Up @@ -149,7 +144,7 @@ export function serveRawFsMiddleware(
url = url.slice(FS_PREFIX.length)
if (isWindows) url = url.replace(/^[A-Z]:/i, '')

req.url = encodePercent(url)
req.url = encodeURIComponent(url)
serveFromRoot(req, res, next)
} else {
next()
Expand Down

0 comments on commit 5cc05bf

Please sign in to comment.