From 8908bc5cbf9a8d65bbd7c5e3276a564f5095cc07 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Wed, 6 Oct 2021 19:04:23 +0900 Subject: [PATCH] net: throw error to given objectMode in connection Fixes: https://github.com/nodejs/node/issues/40336 --- lib/net.js | 7 +++++++ .../test-net-connect-options-invalid.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/parallel/test-net-connect-options-invalid.js diff --git a/lib/net.js b/lib/net.js index ded48732c2e11e..65442c2c74fef7 100644 --- a/lib/net.js +++ b/lib/net.js @@ -194,6 +194,13 @@ function connect(...args) { const normalized = normalizeArgs(args); const options = normalized[0]; debug('createConnection', normalized); + if (options.objectMode) { + throw new ERR_INVALID_ARG_VALUE( + 'options.objectMode', + options.objectMode, + 'is not supported' + ); + } const socket = new Socket(options); if (options.timeout) { diff --git a/test/parallel/test-net-connect-options-invalid.js b/test/parallel/test-net-connect-options-invalid.js new file mode 100644 index 00000000000000..b988a986556cad --- /dev/null +++ b/test/parallel/test-net-connect-options-invalid.js @@ -0,0 +1,19 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +{ + const option = { + ...common.localhostIPv4, + objectMode: true + }; + + assert.throws(() => { + net.createConnection(option); + }, { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError', + message: /The property 'options\.objectMode' is not supported\. Received true/ + }); +}