Skip to content

Commit

Permalink
Added try/catch block around JSON.parse and return an empty object li…
Browse files Browse the repository at this point in the history
…teral

if JSON parsing fails.
  • Loading branch information
Khaless committed Dec 30, 2010
1 parent e57e27e commit ffb0574
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/socket.io/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit ffb0574

Please sign in to comment.