Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ Client.prototype.connect = function(name){

Client.prototype.disconnect = function(){
for (var id in this.sockets) {
this.sockets[id].disconnect();
if (this.sockets.hasOwnProperty(id)) {
this.sockets[id].disconnect();
}
}
this.sockets = {};
this.close();
Expand All @@ -104,7 +106,7 @@ Client.prototype.disconnect = function(){
*/

Client.prototype.remove = function(socket){
if (this.sockets[socket.id]) {
if (this.sockets.hasOwnProperty(socket.id)) {
var nsp = this.sockets[socket.id].nsp.name;
delete this.sockets[socket.id];
delete this.nsps[nsp];
Expand Down Expand Up @@ -204,7 +206,9 @@ Client.prototype.ondecoded = function(packet) {

Client.prototype.onerror = function(err){
for (var id in this.sockets) {
this.sockets[id].onerror(err);
if (this.sockets.hasOwnProperty(id)) {
this.sockets[id].onerror(err);
}
}
this.onclose('client error');
};
Expand All @@ -224,7 +228,9 @@ Client.prototype.onclose = function(reason){

// `nsps` and `sockets` are cleaned up seamlessly
for (var id in this.sockets) {
this.sockets[id].onclose(reason);
if (this.sockets.hasOwnProperty(id)) {
this.sockets[id].onclose(reason);
}
}
this.sockets = {};

Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ Server.prototype.of = function(name, fn){

Server.prototype.close = function(){
for (var id in this.nsps['/'].sockets) {
this.nsps['/'].sockets[id].onclose();
if (this.nsps['/'].sockets.hasOwnProperty(id)) {
this.nsps['/'].sockets[id].onclose();
}
}

this.engine.close();
Expand Down
2 changes: 1 addition & 1 deletion lib/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Namespace.prototype.add = function(client, fn){
*/

Namespace.prototype.remove = function(socket){
if (this.sockets[socket.id]) {
if (this.sockets.hasOwnProperty(socket.id)) {
delete this.sockets[socket.id];
} else {
debug('ignoring remove for %s', socket.id);
Expand Down
3 changes: 1 addition & 2 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function Socket(nsp, client){
this.nsp = nsp;
this.server = nsp.server;
this.adapter = this.nsp.adapter;
this.id = client.id;
this.id = nsp.name + '#' + client.id;
this.client = client;
this.conn = client.conn;
Expand Down Expand Up @@ -223,7 +222,7 @@ Socket.prototype.packet = function(packet, opts){
Socket.prototype.join = function(room, fn){
debug('joining room %s', room);
var self = this;
if (this.rooms[room]) return this;
if (this.rooms.hasOwnProperty(room)) return this;
this.adapter.add(this.id, room, function(err){
if (err) return fn && fn(err);
debug('joined room %s', room);
Expand Down
17 changes: 17 additions & 0 deletions test/socket.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,23 @@ describe('socket.io', function(){
});
});
});

it('should not crash when messing with Object prototype', function(done){
Object.prototype.foo = 'bar';
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);

sio.on('connection', function(s){
s.disconnect(true);
sio.close();
setTimeout(function(){
done();
}, 100);
});
});
});
});

describe('messaging many', function(){
Expand Down