Skip to content

Commit

Permalink
fix(sendRedirect): only encode required chars in meta tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 3, 2022
1 parent dcf208a commit a9b992e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/utils/response.ts
Expand Up @@ -24,15 +24,10 @@ export function defaultContentType (event: CompatibilityEvent, type?: string) {
}

export function sendRedirect (event: CompatibilityEvent, location: string, code = 302) {
const encodedLoc = encodeURI(decodeURI(location))
event.res.statusCode = code
event.res.setHeader('Location', encodedLoc)
// Minimal html document that redirects on client side
const html = `<!DOCTYPE html>
<html>
<head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head>
<body>Redirecting to <a href=${JSON.stringify(encodedLoc)}>${encodedLoc}</a></body>
</html>`
event.res.setHeader('Location', location)
const encodedLoc = location.replace(/"/g, '%22')
const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head></html>`
return send(event, html, MIMES.html)
}

Expand Down

0 comments on commit a9b992e

Please sign in to comment.