Skip to content

Commit

Permalink
Merge pull request socketio#957 from xaroth8088/master
Browse files Browse the repository at this point in the history
Corrects unsafe usage of for..in, permitting socket.io to be used in environments that extend Object, etc.
  • Loading branch information
rauchg committed Jul 21, 2012
2 parents e1fe76a + aeb904f commit 1842218
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function Manager (server, options) {
};

for (var i in options) {
this.settings[i] = options[i];
if (options.hasOwnProperty(i)) {
this.settings[i] = options[i];
}
}

var self = this;
Expand Down Expand Up @@ -129,8 +131,10 @@ function Manager (server, options) {
});

for (var i in transports) {
if (transports[i].init) {
transports[i].init(this);
if (transports.hasOwnProperty(i)) {
if (transports[i].init) {
transports[i].init(this);
}
}
}

Expand Down Expand Up @@ -489,8 +493,10 @@ Manager.prototype.onClientMessage = function (id, packet) {

Manager.prototype.onClientDisconnect = function (id, reason) {
for (var name in this.namespaces) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id] !== 'undefined' &&
typeof this.roomClients[id][name] !== 'undefined');
if (this.namespaces.hasOwnProperty(name)) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id] !== 'undefined' &&
typeof this.roomClients[id][name] !== 'undefined');
}
}

this.onDisconnect(id);
Expand Down Expand Up @@ -524,7 +530,9 @@ Manager.prototype.onDisconnect = function (id, local) {

if (this.roomClients[id]) {
for (var room in this.roomClients[id]) {
this.onLeave(id, room);
if (this.roomClients[id].hasOwnProperty(room)) {
this.onLeave(id, room);
}
}
delete this.roomClients[id]
}
Expand Down Expand Up @@ -674,11 +682,13 @@ Manager.prototype.handleClient = function (data, req) {

// initialize the socket for all namespaces
for (var i in this.namespaces) {
var socket = this.namespaces[i].socket(data.id, true);
if (this.namespaces.hasOwnProperty(i)) {
var socket = this.namespaces[i].socket(data.id, true);

// echo back connect packet and fire connection event
if (i === '') {
this.namespaces[i].handlePacket(data.id, { type: 'connect' });
// echo back connect packet and fire connection event
if (i === '') {
this.namespaces[i].handlePacket(data.id, { type: 'connect' });
}
}
}

Expand Down

0 comments on commit 1842218

Please sign in to comment.