Skip to content

Commit 292c00c

Browse files
[fix] Encode string payloads as strings even if binary supported (#85)
This reverts commit 44c7aa5, which caused string payloads to be encoded as binary (so that huge string payloads were needlessly UTF-8-encoded). Related: socketio/socket.io#2872
1 parent 36ba01d commit 292c00c

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
var utf8 = require('./utf8');
6+
var hasBinary = require('has-binary');
67
var after = require('after');
78
var keys = require('./keys');
89

@@ -217,7 +218,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) {
217218
supportsBinary = null;
218219
}
219220

220-
if (supportsBinary) {
221+
if (supportsBinary && hasBinary(packets)) {
221222
return exports.encodePayloadAsBinary(packets, callback);
222223
}
223224

test/browser/index.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,3 @@ if (Blob) {
99
}
1010

1111
require('./base64_object.js');
12-
13-
// General browser only tests
14-
var parser = require('../../');
15-
var encode = parser.encodePacket;
16-
var decode = parser.decodePacket;
17-
var encPayload = parser.encodePayload;
18-
var decPayload = parser.decodePayload;
19-
20-
describe('basic functionality', function () {
21-
it('should encode string payloads as strings even if binary supported', function (done) {
22-
encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) {
23-
expect(data).to.be.a('string');
24-
done();
25-
});
26-
});
27-
});
28-
29-

test/parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ module.exports = function(parser) {
165165
});
166166
});
167167

168+
describe('basic functionality', function () {
169+
it('should encode string payloads as strings even if binary supported', function (done) {
170+
encPayload([{ type: 'ping' }, { type: 'post' }], true, function(data) {
171+
expect(data).to.be.a('string');
172+
done();
173+
});
174+
});
175+
});
176+
168177
describe('encoding and decoding', function () {
169178
var seen = 0;
170179
it('should encode/decode packets', function (done) {

0 commit comments

Comments
 (0)