From ce32a12d19022f762b9f90f521071e77b3283ac8 Mon Sep 17 00:00:00 2001 From: DuckieTM Date: Sat, 16 Mar 2024 16:38:01 +0100 Subject: [PATCH] Adding back GIF sanitize has been added to it To update also use : yarn install --- package.json | 3 +- src/api/utils/RoomChatFormatter.ts | 74 +++++++++++++----------------- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index d498e1f..bcc8214 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "dependencies": { "@nitrots/nitro-renderer": "file:submodules/renderer", "@tanstack/react-virtual": "^3.0.0-beta.60", + "dompurify": "^3.0.9", "emoji-toolkit": "^7.0.1", "react": "^18.2.0", "react-bootstrap": "^2.7.2", @@ -40,4 +41,4 @@ "sass": "1.64.2", "vite": "^5.0.11" } -} \ No newline at end of file +} diff --git a/src/api/utils/RoomChatFormatter.ts b/src/api/utils/RoomChatFormatter.ts index 17c3c53..a6714cf 100644 --- a/src/api/utils/RoomChatFormatter.ts +++ b/src/api/utils/RoomChatFormatter.ts @@ -136,54 +136,46 @@ const encodeHTML = (str: string) => }); } -export const RoomChatFormatter = (content: string) => -{ +export const RoomChatFormatter = (content: string) => { let result = ''; content = encodeHTML(content); content = content.replace(/\[tag\](.*?)\[\/tag\]/g, '$1'); - - // Youtube link - if(!GetConfiguration('youtube.publish.disabled', false)){ - content = content.replace( - /(?:http:\/\/|https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?.*v=|shorts\/)?([a-zA-Z0-9_-]{11})/g, - ` -
- YouTube IconClick on open video to see the YouTube video -
Open Video
- ` - ); - } - - - if(content.startsWith('@') && content.indexOf('@', 1) > -1) - { - let match = null; - - while((match = /@[a-zA-Z]+@/g.exec(content)) !== null) - { - const colorTag = match[0].toString(); - const colorName = colorTag.substr(1, colorTag.length - 2); - const text = content.replace(colorTag, ''); - - if(!allowedColours.has(colorName)) - { - result = text; - } - else - { - const color = allowedColours.get(colorName); - result = '' + text + ''; - } - break; - } + // Youtube link + if (!GetConfiguration('youtube.publish.disabled', false)) { + content = content.replace( + /(?:http:\/\/|https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?.*v=|shorts\/)?([a-zA-Z0-9_-]{11})/g, + ` +
+ YouTube IconClick on open video to see the YouTube video +
Open Video
+ ` + ); } - else - { + + if (content.includes("giphy.com/media")) { + content = ` +

+ `; + } + + const match = content.match(/@[a-zA-Z]+@/); + if (match) { + const colorTag = match[0].toString(); + const colorName = colorTag.substr(1, colorTag.length - 2); + const text = content.replace(colorTag, ''); + + if (!allowedColours.has(colorName)) { + result = text; + } else { + const color = allowedColours.get(colorName); + result = `${text}`; + } + } else { result = content; } return result; -} \ No newline at end of file +}