From f11296f3a90a24316537d199de72b0244d45a098 Mon Sep 17 00:00:00 2001 From: Moyasee Date: Fri, 3 Oct 2025 15:54:40 +0300 Subject: [PATCH] Fix: eslint error --- src/shared/html-sanitizer.ts | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/shared/html-sanitizer.ts b/src/shared/html-sanitizer.ts index 55af55aa..10c8241d 100644 --- a/src/shared/html-sanitizer.ts +++ b/src/shared/html-sanitizer.ts @@ -1,41 +1,43 @@ function removeZalgoText(text: string): string { - const zalgoRegex = /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/g; - - return text.replace(zalgoRegex, ''); + // eslint-disable-next-line no-misleading-character-class + const zalgoRegex = + /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/g; + + return text.replace(zalgoRegex, ""); } export function sanitizeHtml(html: string): string { - if (!html || typeof html !== 'string') { - return ''; + if (!html || typeof html !== "string") { + return ""; } - let cleanText = html.replace(/<[^>]*>/g, ''); - - const tempDiv = document.createElement('div'); + let cleanText = html.replace(/<[^>]*>/g, ""); + + const tempDiv = document.createElement("div"); tempDiv.innerHTML = cleanText; - cleanText = tempDiv.textContent || tempDiv.innerText || ''; - + cleanText = tempDiv.textContent || tempDiv.innerText || ""; + cleanText = removeZalgoText(cleanText); - - cleanText = cleanText.replace(/\s+/g, ' ').trim(); - + + cleanText = cleanText.replace(/\s+/g, " ").trim(); + if (!cleanText || cleanText.length === 0) { - return ''; + return ""; } - + return cleanText; } export function stripHtml(html: string): string { - if (!html || typeof html !== 'string') { - return ''; + if (!html || typeof html !== "string") { + return ""; } - const tempDiv = document.createElement('div'); + const tempDiv = document.createElement("div"); tempDiv.innerHTML = html; - let cleanText = tempDiv.textContent || tempDiv.innerText || ''; - + let cleanText = tempDiv.textContent || tempDiv.innerText || ""; + cleanText = removeZalgoText(cleanText); - + return cleanText; -} \ No newline at end of file +}