update: escape the html tag from announcmetn

This commit is contained in:
mahyargdz
2025-08-28 09:45:38 +03:30
parent 2bb6859afc
commit 9869e603d3
2 changed files with 18 additions and 2 deletions
@@ -10,6 +10,7 @@ import { SubscriptionPlan } from "../../subscriptions/entities/subscription.enti
import { UserSubscription } from "../../subscriptions/entities/user-subscription.entity";
import { User } from "../../users/entities/user.entity";
import { UsersService } from "../../users/providers/users.service";
import { stripHtmlTags } from "../../utils/providers/string.utils";
import { ANNOUNCEMENT } from "../constants";
import { Announcement } from "../entities/announcement.entity";
import { UserAnnouncement } from "../entities/user-announcement.entity";
@@ -109,7 +110,7 @@ export class AnnouncementProcessor extends WorkerProcessor {
userPhone: user.phone,
userEmail: user.email,
title: announcement.title,
description: announcement.content,
description: stripHtmlTags(announcement.content),
date: announcement.publishAt ?? new Date(),
};
await this.notificationQueue.addAnnouncementNotification(userId, notifData);
+16 -1
View File
@@ -1,4 +1,4 @@
export function truncateIfLong(str: string, maxLength = 30): string {
export function truncateIfLong(str: string, maxLength = 35): string {
if (typeof str !== "string") return str;
return str.length > maxLength ? str.slice(0, maxLength) + "..." : str;
}
@@ -18,3 +18,18 @@ export function randomizeCase(str: string): string {
})
.join("");
}
export function stripHtmlTags(str: string): string {
if (typeof str !== "string") return str;
// Remove HTML tags and decode common HTML entities
return str
.replace(/<[^>]*>/g, "") // Remove all HTML tags
.replace(/&nbsp;/g, " ") // Replace non-breaking spaces
.replace(/&amp;/g, "&") // Replace ampersand entities
.replace(/&lt;/g, "<") // Replace less than entities
.replace(/&gt;/g, ">") // Replace greater than entities
.replace(/&quot;/g, '"') // Replace quote entities
.replace(/&#39;/g, "'") // Replace apostrophe entities
.trim(); // Remove leading/trailing whitespace
}