From 6da6baa213ebe23d518cda0ac68719abc8abfdb9 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 16 Jan 2014 18:50:45 -0500 Subject: [PATCH] more crash fixes to socketS --- src/socket.io/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 8c27bbaa14..91e7dea07a 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -140,8 +140,11 @@ Sockets.init = function() { }); } + if(!payload.name) { + return winston.warn('[socket.io] Empty method name'); + } - var parts = payload.name.split('.'), + var parts = payload.name.toString().split('.'), namespace = parts.slice(0, 1), methodToCall = parts.reduce(function(prev, cur) { if (prev !== null && prev[cur]) { @@ -151,17 +154,16 @@ Sockets.init = function() { } }, Namespaces); - if (methodToCall !== null) { + if(!methodToCall) { + return winston.warn('[socket.io] Unrecognized message: ' + payload.name); + } - if (Namespaces[namespace].before) { - Namespaces[namespace].before(socket, function() { - callMethod(methodToCall); - }); - } else { + if (Namespaces[namespace].before) { + Namespaces[namespace].before(socket, function() { callMethod(methodToCall); - } + }); } else { - winston.warn('[socket.io] Unrecognized message: ' + payload.name); + callMethod(methodToCall); } }); });