diff --git a/src/js/node/net.ts b/src/js/node/net.ts index 97157f97c0..7f66ef8945 100644 --- a/src/js/node/net.ts +++ b/src/js/node/net.ts @@ -1514,6 +1514,8 @@ function lookupAndConnect(self, options) { const host = options.host || "localhost"; let { port, autoSelectFamilyAttemptTimeout, autoSelectFamily } = options; + validateString(host, "options.host"); + if (localAddress && !isIP(localAddress)) { throw $ERR_INVALID_IP_ADDRESS(localAddress); } diff --git a/test/js/node/test/parallel/test-net-connect-options-invalid.js b/test/js/node/test/parallel/test-net-connect-options-invalid.js index 05a5654630..53ce89cac9 100644 --- a/test/js/node/test/parallel/test-net-connect-options-invalid.js +++ b/test/js/node/test/parallel/test-net-connect-options-invalid.js @@ -25,3 +25,16 @@ const net = require('net'); }); }); } + +{ + assert.throws(() => { + net.createConnection({ + host: ['192.168.0.1'], + port: 8080, + }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The "options.host" property must be of type string. Received an instance of Array', + }); +}