From c95ea286edacfb35afde1a52ee95161019362277 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sun, 18 Dec 2016 00:47:42 +0100 Subject: [PATCH] Fix double utf8 encoding for payloads --- lib/browser.js | 4 ++-- lib/index.js | 4 ++-- test/parser.js | 13 ++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/browser.js b/lib/browser.js index 652dc0c..6df90aa 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -331,7 +331,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) { } function encodeOne(packet, doneCallback) { - exports.encodePacket(packet, !isBinary ? false : supportsBinary, true, function(message) { + exports.encodePacket(packet, !isBinary ? false : supportsBinary, false, function(message) { doneCallback(null, setLengthHeader(message)); }); } @@ -407,7 +407,7 @@ exports.decodePayload = function (data, binaryType, callback) { } if (msg.length) { - packet = exports.decodePacket(msg, binaryType, true); + packet = exports.decodePacket(msg, binaryType, false); if (err.type == packet.type && err.data == packet.data) { // parser error in individual packet - ignoring payload diff --git a/lib/index.js b/lib/index.js index 716b1d5..35d9100 100644 --- a/lib/index.js +++ b/lib/index.js @@ -226,7 +226,7 @@ exports.encodePayload = function (packets, supportsBinary, callback) { } function encodeOne(packet, doneCallback) { - exports.encodePacket(packet, supportsBinary, true, function(message) { + exports.encodePacket(packet, supportsBinary, false, function(message) { doneCallback(null, setLengthHeader(message)); }); } @@ -302,7 +302,7 @@ exports.decodePayload = function (data, binaryType, callback) { } if (msg.length) { - packet = exports.decodePacket(msg, binaryType, true); + packet = exports.decodePacket(msg, binaryType, false); if (err.type == packet.type && err.data == packet.data) { // parser error in individual packet - ignoring payload diff --git a/test/parser.js b/test/parser.js index 9a19394..a401f67 100644 --- a/test/parser.js +++ b/test/parser.js @@ -193,6 +193,12 @@ module.exports = function(parser) { }); }); }); + + it('should not utf8 encode when dealing with strings only', function() { + encPayload([{ type: 'message', data: '€€€' }, { type: 'message', data: 'α' }], function(data) { + expect(data).to.eql('4:4€€€2:4α'); + }); + }); }); describe('decoding error handling', function () { @@ -255,13 +261,6 @@ module.exports = function(parser) { }); }); - it('should err on invalid utf8', function () { - decPayload('2:4\uffff', function (packet, index, total) { - var isLast = index + 1 == total; - expect(packet).to.eql(err); - expect(isLast).to.eql(true); - }); - }); }); }); });