From a754959021aa169aae5d3b730b721641d239e3a4 Mon Sep 17 00:00:00 2001 From: Jesse Thompson Date: Tue, 16 Jul 2013 17:45:42 -0700 Subject: [PATCH] C2DM registers itself for the event via the handler, which receives an error and token, but captureToken needs to check that there is no error and that the token exists before attempting to perform a regex match on the token, otherwise we throw an exception that nobody can catch because we're in an unwrapped event handler --- lib/c2dm.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/c2dm.js b/lib/c2dm.js index 4b277d3..3c48834 100644 --- a/lib/c2dm.js +++ b/lib/c2dm.js @@ -40,8 +40,10 @@ util.inherits(C2DM, emitter); exports.C2DM = C2DM; C2DM.prototype.captureToken = function(err, token) { - token = 'auth=' + token.replace(/Auth=/i,''); - this.token = token; + if (!err && token) { + token = 'auth=' + token.replace(/Auth=/i,''); + this.token = token; + } }; C2DM.prototype.login = function(cb) {