From ffb0574a76f460f46a82cb241930ce891e65db70 Mon Sep 17 00:00:00 2001 From: Mathew Rodley Date: Thu, 30 Dec 2010 13:18:27 +1100 Subject: [PATCH] Added try/catch block around JSON.parse and return an empty object literal if JSON parsing fails. --- lib/socket.io/client.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/socket.io/client.js b/lib/socket.io/client.js index afebaf9a44..72bbf918da 100644 --- a/lib/socket.io/client.js +++ b/lib/socket.io/client.js @@ -48,7 +48,11 @@ Client.prototype._onMessage = function(data){ case '~h~': return this._onHeartbeat(messages[i].substr(3)); case '~j~': - messages[i] = JSON.parse(messages[i].substr(3)); + try { + messages[i] = JSON.parse(messages[i].substr(3)); + } catch(e) { + messages[i] = {}; + } break; } this.emit('message', messages[i]);