Skip to content

Commit 01476ac

Browse files
committed
fix(sendRedirect): always encode location uri
1 parent 2fa27e6 commit 01476ac

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils/response.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ export function defaultContentType (event: CompatibilityEvent, type?: string) {
2424
}
2525

2626
export function sendRedirect (event: CompatibilityEvent, location: string, code = 302) {
27+
const encodedLoc = encodeURI(location)
2728
event.res.statusCode = code
28-
event.res.setHeader('Location', location)
29-
// minimal html document that redirects on client side
29+
event.res.setHeader('Location', encodedLoc)
30+
// Minimal html document that redirects on client side
3031
const html = `<!DOCTYPE html>
3132
<html>
32-
<head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head>
33-
<body>Redirecting to <a href=${JSON.stringify(location)}>${encodeURI(location)}</a></body>
33+
<head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head>
34+
<body>Redirecting to <a href=${JSON.stringify(encodedLoc)}>${encodedLoc}</a></body>
3435
</html>`
3536
return send(event, html, MIMES.html)
3637
}

0 commit comments

Comments
 (0)