Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down