Skip to content

Commit 7569258

Browse files
Only convert the current message to a string once the last fragment has been received
1 parent ddbee7b commit 7569258

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/transports/websocket/hybi-16.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function Parser (opts) {
281281
this.expectOffset = 0;
282282
this.expectBuffer = null;
283283
this.expectHandler = null;
284-
this.currentMessage = '';
284+
this.currentMessage = [];
285285
this._maxBuffer = (opts && opts.maxBuffer) || 10E7;
286286
this._dataLength = 0;
287287

@@ -290,10 +290,10 @@ function Parser (opts) {
290290
// text
291291
'1': function(data) {
292292
var finish = function(mask, data) {
293-
self.currentMessage += self.unmask(mask, data);
293+
self.currentMessage.push(self.unmask(mask, data, true));
294294
if (self.state.lastFragment) {
295-
self.emit('data', self.currentMessage);
296-
self.currentMessage = '';
295+
self.emit('data', self.concatBuffers(self.currentMessage).toString('utf8'));
296+
self.currentMessage = [];
297297
}
298298
self.endPacket();
299299
}
@@ -338,11 +338,10 @@ function Parser (opts) {
338338
// binary
339339
'2': function(data) {
340340
var finish = function(mask, data) {
341-
if (typeof self.currentMessage == 'string') self.currentMessage = []; // build a buffer list
342341
self.currentMessage.push(self.unmask(mask, data, true));
343342
if (self.state.lastFragment) {
344343
self.emit('binary', self.concatBuffers(self.currentMessage));
345-
self.currentMessage = '';
344+
self.currentMessage = [];
346345
}
347346
self.endPacket();
348347
}

0 commit comments

Comments
 (0)