Skip to content

Commit a78b334

Browse files
sam-githubbenjamingr
authored andcommitted
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: #2904 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent b801e39 commit a78b334

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/net.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1090,12 +1090,14 @@ function Server(options, connectionListener) {
10901090
connectionListener = options;
10911091
options = {};
10921092
self.on('connection', connectionListener);
1093-
} else {
1093+
} else if (options == null || typeof options === 'object') {
10941094
options = options || {};
10951095

10961096
if (typeof connectionListener === 'function') {
10971097
self.on('connection', connectionListener);
10981098
}
1099+
} else {
1100+
throw new TypeError('options must be an object');
10991101
}
11001102

11011103
this._connections = 0;
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
6+
assert.throws(function() { net.createServer('path'); }, TypeError);
7+
assert.throws(function() { net.createServer(common.PORT); }, TypeError);

0 commit comments

Comments
 (0)