From 3cc2ddc47c8436c82e202189fe114995715e2671 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Thu, 7 Aug 2025 12:55:51 +0700 Subject: [PATCH] feat: prevent html parsing when there is not html --- apps/frontend/src/components/launches/calendar.tsx | 2 +- libraries/helpers/src/utils/strip.html.validation.ts | 6 ++++++ .../src/database/prisma/posts/posts.service.ts | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsx index 86302729..98a95063 100644 --- a/apps/frontend/src/components/launches/calendar.tsx +++ b/apps/frontend/src/components/launches/calendar.tsx @@ -911,7 +911,7 @@ const CalendarItem: FC<{
- {stripHtmlValidation('none', post.content, false, true) || + {stripHtmlValidation('none', post.content, false, true, false) || 'no content'}
diff --git a/libraries/helpers/src/utils/strip.html.validation.ts b/libraries/helpers/src/utils/strip.html.validation.ts index 870494d1..e5abdab4 100644 --- a/libraries/helpers/src/utils/strip.html.validation.ts +++ b/libraries/helpers/src/utils/strip.html.validation.ts @@ -136,8 +136,14 @@ export const stripHtmlValidation = ( val: string, replaceBold = false, none = false, + plain = false, convertMentionFunction?: (idOrHandle: string, name: string) => string ): string => { + + if (plain) { + return val; + } + const value = serialize(parseFragment(val)); if (type === 'html') { diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts index 0a3d7642..06b362dd 100644 --- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts +++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts @@ -44,6 +44,7 @@ type PostWithConditionals = Post & { childrenPost: Post[]; }; + @Injectable() export class PostsService { private storage = UploadFactory.createStorage(); @@ -478,6 +479,7 @@ export class PostsService { p.content, true, false, + !(/<\/?[a-z][\s\S]*>/i.test(p.content)), getIntegration.mentionFormat ), settings: JSON.parse(p.settings || '{}'),