Skip to content

Commit

Permalink
net: throw error to given objectMode in connection
Browse files Browse the repository at this point in the history
Fixes: #40336
  • Loading branch information
watilde committed Oct 6, 2021
1 parent 87da53c commit 8908bc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-net-connect-options-invalid.js
Original file line number Diff line number Diff line change
@@ -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/
});
}

0 comments on commit 8908bc5

Please sign in to comment.