From 28b084af69baf18dffe8f39ed4cbd574c7e3ec53 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 22 Nov 2017 16:03:59 +0200 Subject: [PATCH] Fix #1413 - Handle hex colours when cleaning string --- .../libs/handlebars/ircmessageparser/cleanIrcMessage.js | 3 +-- .../libs/handlebars/ircmessageparser/cleanIrcMessage.js | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js b/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js index d5bacde9..f8f18c86 100644 --- a/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js +++ b/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js @@ -1,4 +1,3 @@ "use strict"; -// TODO: This does not strip hex based colours - issue #1413 -module.exports = (message) => message.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "").trim(); +module.exports = (message) => message.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?|\x04(?:[0-9a-f]{6}(?:,[0-9a-f]{6})?)?/gi, "").trim(); diff --git a/test/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js b/test/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js index 4bca4132..5717ea78 100644 --- a/test/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js +++ b/test/client/js/libs/handlebars/ircmessageparser/cleanIrcMessage.js @@ -38,6 +38,15 @@ describe("cleanIrcMessage", function() { }, { input: "\x02#\x038,9thelounge", expected: "#thelounge", + }, { + input: "\x04DDEEAA,BBEEFF#\x038,9thelou\x04FFAACC\x0311\x04nge", + expected: "#thelounge", + }, { + input: "\x04ddEEffhex\x04 color\x04EEffCC,AAaaCC clean", + expected: "hex color clean", + }, { + input: "\x04 AAaaAA\x03 11 \x04Invalid,Hex ", + expected: "AAaaAA 11 Invalid,Hex", }]; const actual = testCases.map((testCase) => cleanIrcMessage(testCase.input));