Skip to content

Commit

Permalink
Merge pull request #41 from rase-/fix/parse-error
Browse files Browse the repository at this point in the history
Fix parse error
  • Loading branch information
rauchg committed Jan 17, 2015
2 parents b8ec539 + b21717b commit 3f7dde9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
8 changes: 5 additions & 3 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
return encodeBlob(packet, supportsBinary, callback);
}

// might be an object with { base64: true, data: dataAsBase64String }
// might be an object with { base64: true, data: dataAsBase64String }
if (data && data.base64) {
return encodeBase64Object(packet, callback);
}
Expand Down Expand Up @@ -297,7 +297,9 @@ exports.encodePayload = function (packets, supportsBinary, callback) {
supportsBinary = null;
}

if (supportsBinary && hasBinary(packets)) {
var isBinary = hasBinary(packets);

if (supportsBinary && isBinary) {
if (Blob && !dontSendBlobs) {
return exports.encodePayloadAsBlob(packets, callback);
}
Expand All @@ -314,7 +316,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) {
}

function encodeOne(packet, doneCallback) {
exports.encodePacket(packet, supportsBinary, true, function(message) {
exports.encodePacket(packet, !isBinary ? false : supportsBinary, true, function(message) {
doneCallback(null, setLengthHeader(message));
});
}
Expand Down
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

var utf8 = require('utf8');
var hasBinary = require('has-binary');
var after = require('after');
var keys = require('./keys');

Expand Down Expand Up @@ -227,7 +226,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) {
supportsBinary = null;
}

if (supportsBinary && hasBinary(packets)) {
if (supportsBinary) {
return exports.encodePayloadAsBinary(packets, callback);
}

Expand Down
18 changes: 18 additions & 0 deletions test/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,21 @@ if (Blob) {
}

require('./base64_object.js');

// General browser only tests
var parser = require('../../');
var encode = parser.encodePacket;
var decode = parser.decodePacket;
var encPayload = parser.encodePayload;
var decPayload = parser.decodePayload;

describe('basic functionality', function () {
it('should encode string payloads as strings even if binary supported', function (done) {
encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) {
expect(data).to.be.a('string');
done();
});
});
});


9 changes: 0 additions & 9 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ module.exports = function(parser) {
});
});

describe('basic functionality', function () {
it('should encode string payloads as strings even if binary supported', function (done) {
encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) {
expect(data).to.be.a('string');
done();
});
});
});

describe('encoding and decoding', function () {
var seen = 0;
it('should encode/decode packets', function (done) {
Expand Down

0 comments on commit 3f7dde9

Please sign in to comment.