Skip to content

Commit

Permalink
Merge pull request from GHSA-52rh-5rpj-c3w6
Browse files Browse the repository at this point in the history
Split lines on CR as well as CR/CRLF
  • Loading branch information
tadzik committed May 4, 2022
2 parents 7130026 + 48bff4f commit a6552e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/irc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,9 +1407,11 @@ export class Client extends EventEmitter {
if (typeof text === 'undefined') {
return;
}
await Promise.all(text.toString().split(/\r?\n/).filter((line) =>
line.length > 0
).map((line) => this.say(channel, '\u0001ACTION ' + line + '\u0001')));
await Promise.all(
this._splitMessage(
channel + '\u0001ACTION ' + '\u0001', text
).map((line) => this.say(channel, '\u0001ACTION ' + line + '\u0001'))
);
}

// E.g. isUserPrefixMorePowerfulThan("@", "&")
Expand Down Expand Up @@ -1441,7 +1443,7 @@ export class Client extends EventEmitter {
if (!text) {
return [];
}
return text.toString().split(/\r?\n/).filter((line) => line.length > 0)
return text.toString().split(/\r\n|\r|\n/).filter((line) => line.length > 0)
.map((line) => splitLongLines(line, maxLength))
.reduce((a, b) => a.concat(b), []);
}
Expand Down
10 changes: 10 additions & 0 deletions test/test-split-messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { Client } = require('../lib/irc');
const test = require('tape');

test('irc.Client.getSplitMessages', function(t) {
const client = new Client('localhost', 'test', { autoConnect: false });
t.deepEqual(client.getSplitMessages('#chan', 'foo\nbar\nbaz'), ['foo', 'bar', 'baz']);
t.deepEqual(client.getSplitMessages('#chan', 'foo\r\nbar\r\nbaz'), ['foo', 'bar', 'baz']);
t.deepEqual(client.getSplitMessages('#chan', 'foo\rbar\rbaz'), ['foo', 'bar', 'baz']);
t.end();
});

0 comments on commit a6552e5

Please sign in to comment.