From 2e680180596f558d296e1c302b41f808d5f068c0 Mon Sep 17 00:00:00 2001 From: Moyasee Date: Fri, 3 Oct 2025 15:56:02 +0300 Subject: [PATCH] fix: eslint error --- src/shared/html-sanitizer.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/shared/html-sanitizer.ts b/src/shared/html-sanitizer.ts index 10c8241d..7d7012f6 100644 --- a/src/shared/html-sanitizer.ts +++ b/src/shared/html-sanitizer.ts @@ -6,6 +6,21 @@ function removeZalgoText(text: string): string { return text.replace(zalgoRegex, ""); } +function decodeHtmlEntities(text: string): string { + const entityMap: { [key: string]: string } = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + ' ': ' ', + }; + + return text.replace(/&[#\w]+;/g, (entity) => { + return entityMap[entity] || entity; + }); +} + export function sanitizeHtml(html: string): string { if (!html || typeof html !== "string") { return ""; @@ -13,9 +28,7 @@ export function sanitizeHtml(html: string): string { let cleanText = html.replace(/<[^>]*>/g, ""); - const tempDiv = document.createElement("div"); - tempDiv.innerHTML = cleanText; - cleanText = tempDiv.textContent || tempDiv.innerText || ""; + cleanText = decodeHtmlEntities(cleanText); cleanText = removeZalgoText(cleanText);