From 866ee4d565b3a6f88b2db0e0e699132b37375990 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 25 Nov 2022 08:36:29 +0100 Subject: [PATCH] fix(rocketchat): Replace invalid link characters --- back/models/chat.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/back/models/chat.js b/back/models/chat.js index 95a1e2c29..19f73ca4a 100644 --- a/back/models/chat.js +++ b/back/models/chat.js @@ -4,4 +4,21 @@ module.exports = Self => { require('../methods/chat/sendCheckingPresence')(Self); require('../methods/chat/notifyIssues')(Self); require('../methods/chat/sendQueued')(Self); + + Self.observe('before save', async function(ctx) { + if (!ctx.isNewInstance) return; + + let {message} = ctx.instance; + if (!message) return; + + const parts = message.match(/(?<=\[)[A-Za-z0-9()*\s]*(?=])/g) || []; + const replacedParts = parts.map(part => { + return part.replace(/[*()]/g, ''); + }); + + for (const [index, part] of parts.entries()) + message = message.replace(part, replacedParts[index]); + + ctx.instance.message = message; + }); };