From 3460b0544c105ed445099e6b23b99b8529812b8a Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 2 Jan 2014 18:32:49 -0500 Subject: [PATCH] Fix corner case causing TypeError in userJoin I believe this issue was caused by a single user in the channel being kicked for a duplicate login, thereby unloading the channel while the for loop was iterating, so this.users became undefined before the loop exited and thus there was a TypeError for reading this.users.length --- lib/channel.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index be089cf4..b00bdd7b 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -881,16 +881,16 @@ Channel.prototype.userJoin = function(user, password) { Logger.errlog.log("keys: " + Object.keys(this).join(",")); return; } - for(var i = 0; i < this.users.length; i++) { - if(this.users[i].name.toLowerCase() == user.name.toLowerCase()) { - if (this.users[i] == user) { + this.users.forEach(function (u) { + if(u.name.toLowerCase() == user.name.toLowerCase()) { + if (u == user) { Logger.errlog.log("Wat: userJoin() called on user "+ "already in the channel"); - break; + return; } - this.kick(this.users[i], "Duplicate login"); + this.kick(u, "Duplicate login"); } - } + }); } this.users.push(user);