From c6d426259ceebe6fe2a0d63744e8a1bc4270641b Mon Sep 17 00:00:00 2001 From: Justin Gallardo Date: Mon, 2 Mar 2015 12:34:53 -0800 Subject: [PATCH] fix(travis): Add node 0.12 and iojs to travis. update node-icu fix(irc): Fix double connection callback. fix(test helpers): Split on newlines sooner so it has to happen less. --- .travis.yml | 2 ++ lib/irc.js | 47 ++++++++++++++++++----------------------------- package.json | 2 +- test/helpers.js | 6 +++--- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index da218a4b..05308a13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: + - "0.12" - "0.10" + - "iojs" before_install: - sudo apt-get -y install libicu-dev - npm install -g npm diff --git a/lib/irc.js b/lib/irc.js index 9bc96d3e..b0894ab1 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -633,6 +633,21 @@ Client.prototype.chanData = function(name, create) { return this.chans[key]; }; +Client.prototype._connectionHandler = function() { + if (this.opt.webirc.ip && this.opt.webirc.pass && this.opt.webirc.host) { + this.send('WEBIRC', this.opt.webirc.pass, this.opt.userName, this.opt.webirc.host, this.opt.webirc.ip); + } + if (this.opt.password) { + this.send('PASS', this.opt.password); + } + if (this.opt.debug) + util.log('Sending irc NICK/USER'); + this.send('NICK', this.opt.nick); + this.nick = this.opt.nick; + this.send('USER', this.opt.userName, 8, '*', this.opt.realName); + this.emit('connect'); +}; + Client.prototype.connect = function(retryCount, callback) { if (typeof (retryCount) === 'function') { callback = retryCount; @@ -686,25 +701,15 @@ Client.prototype.connect = function(retryCount, callback) { self.conn.authorizationError === 'CERT_HAS_EXPIRED') { util.log('Connecting to server with expired certificate'); } - if (self.opt.webirc.ip && self.opt.webirc.pass && self.opt.webirc.host) { - self.send('WEBIRC', self.opt.webirc.pass, self.opt.userName, self.opt.webirc.host, self.opt.webirc.ip); - } - if (self.opt.password) { - self.send('PASS', self.opt.password); - } - if (self.opt.debug) - util.log('Sending irc NICK/USER'); - self.send('NICK', self.opt.nick); - self.nick = self.opt.nick; - self.send('USER', self.opt.userName, 8, '*', self.opt.realName); - self.emit('connect'); + + self._connectionHandler(); } else { // authorization failed util.log(self.conn.authorizationError); } }); } else { - self.conn = net.createConnection(connectionOpts); + self.conn = net.createConnection(connectionOpts, self._connectionHandler.bind(self)); } self.conn.requestedDisconnect = false; self.conn.setTimeout(0); @@ -713,22 +718,6 @@ Client.prototype.connect = function(retryCount, callback) { self.conn.setEncoding('utf8'); } - self.conn.addListener('connect', function() { - if (self.opt.sasl) { - // see http://ircv3.atheme.org/extensions/sasl-3.1 - self.send('CAP REQ', 'sasl'); - } - if (self.opt.webirc.ip && self.opt.webirc.pass && self.opt.webirc.host) { - self.send('WEBIRC', self.opt.webirc.pass, self.opt.userName, self.opt.webirc.host, self.opt.webirc.ip); - } else if (self.opt.password) { - self.send('PASS', self.opt.password); - } - self.send('NICK', self.opt.nick); - self.nick = self.opt.nick; - self.send('USER', self.opt.userName, 8, '*', self.opt.realName); - self.emit('connect'); - }); - var buffer = new Buffer(''); self.conn.addListener('data', function(chunk) { diff --git a/package.json b/package.json index 1fd07288..ecf81cb1 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "irc-colors": "^1.1.0" }, "optionalDependencies": { - "iconv": "~2.1.4", + "iconv": "~2.1.6", "node-icu-charset-detector": "0.1.0" }, "devDependencies": { diff --git a/test/helpers.js b/test/helpers.js index b1f39ffe..6051da68 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -29,8 +29,8 @@ var MockIrcd = function(port, encoding, isSecure) { this.server = connectionClass.createServer(options, function(c) { c.on('data', function(data) { - var msg = data.toString(self.encoding); - self.incoming = self.incoming.concat(msg.split('\r\n')); + var msg = data.toString(self.encoding).split('\r\n').filter(function(m) { return m; }); + self.incoming = self.incoming.concat(msg); }); self.on('send', function(data) { @@ -56,7 +56,7 @@ MockIrcd.prototype.close = function() { }; MockIrcd.prototype.getIncomingMsgs = function() { - return this.incoming.filter(function(msg) { return msg; }); + return this.incoming; }; var fixtures = require('./data/fixtures');