diff --git a/lib/browser.js b/lib/browser.js index e7debfb..652dc0c 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -222,8 +222,11 @@ exports.encodeBase64Packet = function(packet, callback) { */ exports.decodePacket = function (data, binaryType, utf8decode) { + if (data === undefined) { + return err; + } // String data - if (typeof data == 'string' || data === undefined) { + if (typeof data == 'string') { if (data.charAt(0) == 'b') { return exports.decodeBase64Packet(data.substr(1), binaryType); } diff --git a/lib/index.js b/lib/index.js index e9dafd9..716b1d5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -118,8 +118,11 @@ exports.encodeBase64Packet = function(packet, callback){ */ exports.decodePacket = function (data, binaryType, utf8decode) { + if (data === undefined) { + return err; + } // String data - if (typeof data == 'string' || data === undefined) { + if (typeof data == 'string') { if (data.charAt(0) == 'b') { return exports.decodeBase64Packet(data.substr(1), binaryType); } diff --git a/test/parser.js b/test/parser.js index da852d8..9a19394 100644 --- a/test/parser.js +++ b/test/parser.js @@ -129,6 +129,10 @@ module.exports = function(parser) { describe('decoding error handing', function () { var err = { type: 'error', data: 'parser error' }; + it('should disallow empty payload', function () { + expect(decode(undefined)).to.eql(err); + }); + it('should disallow bad format', function () { expect(decode(':::')).to.eql(err); });