Merge pull request #1731 from thelounge/xpaw/fix-1413

Handle hex colours when cleaning string
This commit is contained in:
Jérémie Astori 2017-11-22 16:29:08 -05:00 committed by GitHub
commit 643a8222a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -1,4 +1,5 @@
"use strict"; "use strict";
// TODO: This does not strip hex based colours - issue #1413 const matchFormatting = /\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?|\x04(?:[0-9a-f]{6}(?:,[0-9a-f]{6})?)?/gi;
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(matchFormatting, "").trim();

View file

@ -38,6 +38,15 @@ describe("cleanIrcMessage", function() {
}, { }, {
input: "\x02#\x038,9thelounge", input: "\x02#\x038,9thelounge",
expected: "#thelounge", 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)); const actual = testCases.map((testCase) => cleanIrcMessage(testCase.input));