fix templete
This commit is contained in:
+16
-10
@@ -89,22 +89,28 @@ export const sanitizeEmailHTML = (html: string): string => {
|
||||
// Remove link tags (CSS files)
|
||||
sanitized = sanitized.replace(/<link[^>]*>/gi, "");
|
||||
|
||||
// Remove all style attributes
|
||||
sanitized = sanitized.replace(/\s*style\s*=\s*["'][^"']*["']/gi, "");
|
||||
|
||||
// Remove font-family and other font-related CSS properties
|
||||
sanitized = sanitized
|
||||
.replace(/font-family\s*:\s*[^;]*;?/gi, "")
|
||||
.replace(/font-size\s*:\s*[^;]*;?/gi, "")
|
||||
.replace(/font-weight\s*:\s*[^;]*;?/gi, "")
|
||||
.replace(/color\s*:\s*[^;]*;?/gi, "");
|
||||
|
||||
// Remove script tags for security
|
||||
sanitized = sanitized.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "");
|
||||
|
||||
// Remove potentially harmful attributes
|
||||
sanitized = sanitized.replace(/\s*on\w+\s*=\s*["'][^"']*["']/gi, "");
|
||||
|
||||
// فقط font-family و font-size رو از inline styles حذف کن، بقیه رو حفظ کن
|
||||
sanitized = sanitized.replace(
|
||||
/style\s*=\s*["']([^"']*?)["']/gi,
|
||||
(match, styles) => {
|
||||
// فقط font-family و font-size رو حذف کن
|
||||
const cleanedStyles = styles
|
||||
.replace(/font-family\s*:\s*[^;]*;?/gi, "")
|
||||
.replace(/font-size\s*:\s*[^;]*;?/gi, "")
|
||||
.replace(/font-weight\s*:\s*[^;]*;?/gi, "")
|
||||
.replace(/;\s*;/g, ";") // حذف سمیکالنهای اضافی
|
||||
.replace(/^\s*;\s*|\s*;\s*$/g, ""); // حذف سمیکالنهای ابتدا و انتها
|
||||
|
||||
return cleanedStyles ? `style="${cleanedStyles}"` : "";
|
||||
}
|
||||
);
|
||||
|
||||
return sanitized;
|
||||
} catch (error) {
|
||||
console.error("خطا در پاکسازی HTML:", error);
|
||||
|
||||
Reference in New Issue
Block a user