Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ const kSetNoDelay = Symbol('kSetNoDelay');

function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options);
if (options?.objectMode) {
throw new ERR_INVALID_ARG_VALUE(
'options.objectMode',
options.objectMode,
'is not supported'
);
} else if (options?.readableObjectMode || options?.writableObjectMode) {
throw new ERR_INVALID_ARG_VALUE(
`options.${
options.readableObjectMode ? 'readableObjectMode' : 'writableObjectMode'
}`,
options.readableObjectMode || options.writableObjectMode,
'is not supported'
);
}

this.connecting = false;
// Problem with this is that users can supply their own handle, that may not
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-net-connect-options-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');

{
const invalidKeys = [
'objectMode',
'readableObjectMode',
'writableObjectMode',
];
invalidKeys.forEach((invalidKey) => {
const option = {
port: 8080,
[invalidKey]: true
};
const message = `The property 'options.${invalidKey}' is not supported. Received true`;

assert.throws(() => {
net.createConnection(option);
}, {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: new RegExp(message)
});
});
}
27 changes: 27 additions & 0 deletions test/parallel/test-socket-options-invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');

{
const invalidKeys = [
'objectMode',
'readableObjectMode',
'writableObjectMode',
];
invalidKeys.forEach((invalidKey) => {
const option = {
[invalidKey]: true
};
const message = `The property 'options.${invalidKey}' is not supported. Received true`;

assert.throws(() => {
const socket = new net.Socket(option);
socket.connect({ port: 8080 });
}, {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: new RegExp(message)
});
});
}