Skip to content

Commit

Permalink
[fix] Encode string payloads as strings even if binary supported (#85)
Browse files Browse the repository at this point in the history
This reverts commit 44c7aa5, which caused string payloads to be encoded
as binary (so that huge string payloads were needlessly UTF-8-encoded).

Related: #2872
  • Loading branch information
darrachequesne authored Mar 6, 2017
1 parent 36ba01d commit 292c00c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

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

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

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

Expand Down
18 changes: 0 additions & 18 deletions test/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,3 @@ 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: 9 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ 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 292c00c

Please # to comment.