From d1e5a8f4927dd03d0103c8faf2c0adcb1fd9cb76 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 13 Feb 2018 13:05:49 +0200 Subject: [PATCH] Render MOTD with a single message --- .../js/libs/handlebars/ircmessageparser/parseStyle.js | 3 ++- src/plugins/irc-events/motd.js | 10 ++++------ test/client/js/libs/handlebars/parse.js | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/client/js/libs/handlebars/ircmessageparser/parseStyle.js b/client/js/libs/handlebars/ircmessageparser/parseStyle.js index 39e06abe..16deb790 100644 --- a/client/js/libs/handlebars/ircmessageparser/parseStyle.js +++ b/client/js/libs/handlebars/ircmessageparser/parseStyle.js @@ -19,7 +19,8 @@ const colorRx = /^(\d{1,2})(?:,(\d{1,2}))?/; const hexColorRx = /^([0-9a-f]{6})(?:,([0-9a-f]{6}))?/i; // Represents all other control codes that to be ignored/filtered from the text -const controlCodesRx = /[\u0000-\u001F]/g; +// This regex allows line feed character +const controlCodesRx = /[\u0000-\u0009\u000B-\u001F]/g; // Converts a given text into an array of objects, each of them representing a // similarly styled section of the text. Each object carries the `text`, style diff --git a/src/plugins/irc-events/motd.js b/src/plugins/irc-events/motd.js index 001bbf1a..1d222287 100644 --- a/src/plugins/irc-events/motd.js +++ b/src/plugins/irc-events/motd.js @@ -9,13 +9,11 @@ module.exports = function(irc, network) { const lobby = network.channels[0]; if (data.motd) { - data.motd.trim().split("\n").forEach((text) => { - const msg = new Msg({ - type: Msg.Type.MOTD, - text: text, - }); - lobby.pushMessage(client, msg); + const msg = new Msg({ + type: Msg.Type.MOTD, + text: data.motd, }); + lobby.pushMessage(client, msg); } if (data.error) { diff --git a/test/client/js/libs/handlebars/parse.js b/test/client/js/libs/handlebars/parse.js index 61f582b0..416f5bbd 100644 --- a/test/client/js/libs/handlebars/parse.js +++ b/test/client/js/libs/handlebars/parse.js @@ -19,10 +19,10 @@ describe("parse Handlebars helper", () => { expect(actual).to.deep.equal(expected); }); - it("should skip control codes", () => { + it("should skip all <32 ASCII codes except linefeed", () => { const testCases = [{ - input: "text\x01with\x04control\x05codes", - expected: "textwithcontrolcodes", + input: "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1B\x1D\x1D\x1E\x1Ftext\x0Awithcontrolcodestest", + expected: 'text\nwithcontrolcodestest', }]; const actual = testCases.map((testCase) => parse(testCase.input));