Use String.replaceAll() instead of String.replace() with /g flag (S7781)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 00:29:28 +08:00
parent 2b0dadedd4
commit ebd198e28d
5 changed files with 9 additions and 9 deletions

View File

@@ -12,9 +12,9 @@
*/
export function escapeHtml(str) {
return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#039;");
}