Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move binary detection to the parser #2923

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/namespace.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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