Skip to content

Commit

Permalink
Fixes #419. Set a default maxLength in case a message is sent before …
Browse files Browse the repository at this point in the history
…it could be properly set.
  • Loading branch information
jirwin committed Jan 29, 2016
1 parent 0c84741 commit ce2bf24
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ Client.prototype.action = function(channel, text) {
};

Client.prototype._splitLongLines = function(words, maxLength, destination) {
maxLength = maxLength || 450; // If maxLength hasn't been initialized yet, prefer an arbitrarily low line length over crashing.
if (words.length == 0) {
return destination;
}
Expand Down
8 changes: 7 additions & 1 deletion test/data/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,11 @@
"maxLength": 5,
"result": ["abc", "abcde", "f abc", "abcd", "abc"]
}
]
],
"_splitLongLines_no_max": [
{
"input": "abcdefghijklmnopqrstuvwxyz",
"result": ["abcdefghijklmnopqrstuvwxyz"]
}
]
}
20 changes: 20 additions & 0 deletions test/test-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,23 @@ test ('splitting of long lines', function(t) {
});
mock.close();
});

test ('splitting of long lines with no maxLength defined.', function(t) {
var port = 6667;
var mock = testHelpers.MockIrcd(port, 'utf-8', false);
var client = new irc.Client('localhost', 'testbot', {
secure: false,
selfSigned: true,
port: port,
retryCount: 0,
debug: true
});

var group = testHelpers.getFixtures('_splitLongLines_no_max');
console.log(group.length);
t.plan(group.length);
group.forEach(function(item) {
t.deepEqual(client._splitLongLines(item.input, null, []), item.result);
});
mock.close();
});

0 comments on commit ce2bf24

Please sign in to comment.