From 213339be7a15bc25a99fd6d000b730371294ceb6 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Sun, 13 Sep 2015 19:49:35 -0700 Subject: [PATCH 1/2] 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. --- lib/net.js | 4 +++- test/parallel/test-net-server-options.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-net-server-options.js diff --git a/lib/net.js b/lib/net.js index 8245601e51733a..2c88a235b3a575 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1080,12 +1080,14 @@ function Server(options, connectionListener) { connectionListener = options; options = {}; self.on('connection', connectionListener); - } else { + } else if(options == null || typeof options === 'object') { options = options || {}; if (typeof connectionListener === 'function') { self.on('connection', connectionListener); } + } else { + throw new TypeError('options must be an object'); } this._connections = 0; diff --git a/test/parallel/test-net-server-options.js b/test/parallel/test-net-server-options.js new file mode 100644 index 00000000000000..553b845f37d053 --- /dev/null +++ b/test/parallel/test-net-server-options.js @@ -0,0 +1,7 @@ +'use strict'; +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); + +assert.throws(function() { net.createServer('path'); }, TypeError); +assert.throws(function() { net.createServer(common.PORT); }, TypeError); From 4c30369ce767dcc20f477f70c7303f4170fa34ba Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 16 Sep 2015 12:10:48 -0700 Subject: [PATCH 2/2] fixup! net: type check createServer options object --- test/parallel/test-net-server-options.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-net-server-options.js b/test/parallel/test-net-server-options.js index 553b845f37d053..1445c3e6b8245f 100644 --- a/test/parallel/test-net-server-options.js +++ b/test/parallel/test-net-server-options.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); +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);