Skip to content

Commit

Permalink
[feat] Move binary detection to the parser (#2923)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 24, 2017
1 parent 199eec6 commit 87b06ad
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
6 changes: 1 addition & 5 deletions lib/namespace.js
Expand Up @@ -7,7 +7,6 @@ var Socket = require('./socket');
var Emitter = require('events').EventEmitter;
var parser = require('socket.io-parser');
var debug = require('debug')('socket.io:namespace');
var hasBin = require('has-binary');

/**
* Module exports.
Expand Down Expand Up @@ -210,10 +209,7 @@ Namespace.prototype.emit = function(ev){
} else {
// set up packet object
var args = Array.prototype.slice.call(arguments);
var parserType = parser.EVENT; // default
if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary

var packet = { type: parserType, data: args };
var packet = { type: parser.EVENT, data: args };

if ('function' == typeof args[args.length - 1]) {
throw new Error('Callbacks are not supported when broadcasting');
Expand Down
6 changes: 2 additions & 4 deletions lib/socket.js
Expand Up @@ -7,7 +7,6 @@ var Emitter = require('events').EventEmitter;
var parser = require('socket.io-parser');
var url = require('url');
var debug = require('debug')('socket.io:socket');
var hasBin = require('has-binary');
var assign = require('object-assign');

/**
Expand Down Expand Up @@ -143,7 +142,7 @@ Socket.prototype.emit = function(ev){
} else {
var args = Array.prototype.slice.call(arguments);
var packet = {
type: hasBin(args) ? parser.BINARY_EVENT : parser.EVENT,
type: parser.EVENT,
data: args
};

Expand Down Expand Up @@ -375,10 +374,9 @@ Socket.prototype.ack = function(id){
var args = Array.prototype.slice.call(arguments);
debug('sending ack %j', args);

var type = hasBin(args) ? parser.BINARY_ACK : parser.ACK;
self.packet({
id: id,
type: type,
type: parser.ACK,
data: args
});

Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -26,11 +26,10 @@
"dependencies": {
"debug": "2.3.3",
"engine.io": "2.0.2",
"has-binary": "0.1.7",
"object-assign": "4.1.0",
"socket.io-adapter": "~1.1.0",
"socket.io-client": "socketio/socket.io-client",
"socket.io-parser": "2.3.1"
"socket.io-parser": "~3.1.1"
},
"devDependencies": {
"babel-preset-es2015": "6.3.13",
Expand Down
4 changes: 3 additions & 1 deletion test/socket.io.js
Expand Up @@ -1730,8 +1730,10 @@ describe('socket.io', function(){
});
});

it('should not crash when messing with Object prototype', function(done){
it('should not crash when messing with Object prototype (and other globals)', function(done){
Object.prototype.foo = 'bar';
global.File = '';
global.Blob = [];
var srv = http();
var sio = io(srv);
srv.listen(function(){
Expand Down

0 comments on commit 87b06ad

Please sign in to comment.