From 80e3decbdc09abc9b1113c233ab67b3b00abc1fc Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Wed, 6 Oct 2021 18:52:16 +0900 Subject: [PATCH] net: throw error to given objectMode in connection Fixes: https://github.com/nodejs/node/issues/40336 --- lib/net.js | 3 +++ .../test-net-connect-options-invalid.js | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/parallel/test-net-connect-options-invalid.js diff --git a/lib/net.js b/lib/net.js index ded48732c2e11e..95e36cda07c089 100644 --- a/lib/net.js +++ b/lib/net.js @@ -194,6 +194,9 @@ 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..e30ab86a55bc3f --- /dev/null +++ b/test/parallel/test-net-connect-options-invalid.js @@ -0,0 +1,20 @@ +'use strict'; +const assert = require('assert'); +const net = require('net'); + +{ + const ArgValueInvalidError = { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError' + }; + + const option = {objectMode: true}; + + assert.throws(() => { + net.createConnection(option); + }, { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError', + message: /The property 'options.objectMode' is not supported. Received true/ + }); +}