net: type check createServer options object
net.createServer('aPipe') and net.createServer(8080) are mistakes, and now throw a TypeError instead of silently being treated as an object. PR-URL: https://github.com/nodejs/node/pull/2904 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
b801e39266
commit
a78b3344f8
@ -1090,12 +1090,14 @@ function Server(options, connectionListener) {
|
|||||||
connectionListener = options;
|
connectionListener = options;
|
||||||
options = {};
|
options = {};
|
||||||
self.on('connection', connectionListener);
|
self.on('connection', connectionListener);
|
||||||
} else {
|
} else if (options == null || typeof options === 'object') {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if (typeof connectionListener === 'function') {
|
if (typeof connectionListener === 'function') {
|
||||||
self.on('connection', connectionListener);
|
self.on('connection', connectionListener);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new TypeError('options must be an object');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._connections = 0;
|
this._connections = 0;
|
||||||
|
7
test/parallel/test-net-server-options.js
Normal file
7
test/parallel/test-net-server-options.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const net = require('net');
|
||||||
|
|
||||||
|
assert.throws(function() { net.createServer('path'); }, TypeError);
|
||||||
|
assert.throws(function() { net.createServer(common.PORT); }, TypeError);
|
Loading…
x
Reference in New Issue
Block a user