Skip to content

Commit 617073c

Browse files
committed
improvement(chat): hoist HTML escape map to module-level constant
1 parent 6636456 commit 617073c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

apps/sim/app/chat/components/message/message.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,19 @@ export interface ChatMessage {
3838
files?: ChatFile[]
3939
}
4040

41+
const HTML_ESCAPES: Record<string, string> = {
42+
'&': '&amp;',
43+
'<': '&lt;',
44+
'>': '&gt;',
45+
'"': '&quot;',
46+
"'": '&#39;',
47+
} as const
48+
4149
/**
4250
* Escapes HTML entities so untrusted strings are safe to interpolate into markup.
4351
*/
4452
function escapeHtml(value: string): string {
45-
return value.replace(
46-
/[&<>"']/g,
47-
(c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c] || c
48-
)
53+
return value.replace(/[&<>"']/g, (c) => HTML_ESCAPES[c] || c)
4954
}
5055

5156
/**

0 commit comments

Comments
 (0)