Skip to content

Commit 2df5d82

Browse files
pi0claude
andcommitted
refactor(response): use single-pass replace for HTML escaping
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 14be4bc commit 2df5d82

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/utils/response.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ export function redirect(
4444
status: number = 302,
4545
statusText?: string,
4646
): HTTPResponse {
47-
const htmlLoc = location
48-
.replace(/&/g, "&amp;")
49-
.replace(/"/g, "&quot;")
50-
.replace(/</g, "&lt;")
51-
.replace(/>/g, "&gt;");
47+
const htmlLoc = location.replace(/[&"<>]/g, (c) => ({ "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" })[c]!);
5248
const body = /* html */ `<html><head><meta http-equiv="refresh" content="0; url=${htmlLoc}" /></head></html>`;
5349
return new HTTPResponse(body, {
5450
status,

0 commit comments

Comments
 (0)