From 4cf31f6a5764d2d9776ca4672fb474faef2d4a61 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 24 Jun 2025 21:46:56 -0800 Subject: [PATCH] node: sync test-net-connect-options-invalid.js (#20607) --- src/js/node/net.ts | 2 ++ .../parallel/test-net-connect-options-invalid.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) 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', + }); +}