Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Process decoding after all the chunks have been received.

Prevent bugs that can occur when decode the large chunk with
multibyte encoding.
  • Loading branch information...
commit 639432c9bcc769f7df432e4a2dd98c0c5d61d474 1 parent 555ec66
HyeonJe Jun authored
Showing with 18 additions and 5 deletions.
  1. +18 −5 lib/irc.js
View
23 lib/irc.js
@@ -635,12 +635,25 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
self.send("USER", self.opt.userName, 8, "*", self.opt.realName);
self.emit("connect");
});
- var buffer = '';
+ var buffer = new Buffer('');
self.conn.addListener("data", function (chunk) {
- // it's source of bugs if original encoding is multibyte and message is large
- buffer += self.decode(chunk);
- var lines = buffer.split("\r\n");
- buffer = lines.pop();
+ if(typeof(chunk) == 'string') {
+ buffer += chunk;
+ }
+ else {
+ buffer = Buffer.concat([buffer, chunk]);
+ }
+
+ var lines = self.decode(buffer).toString().split("\r\n");
+ if( lines.pop() ) {
+ // if buffer is not ended with \r\n, there's more chunks.
+ return;
+ }
+ else {
+ // else, initialize the buffer.
+ buffer = new Buffer('');
+ }
+
lines.forEach(function (line) {
var message = parseMessage(line, self.opt.stripColors);
try {
Please sign in to comment.
Something went wrong with that request. Please try again.