Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a672be5

Browse filesBrowse files
watildetargos
authored andcommitted
net: throw error to object mode in Socket
Fixes: #40336 PR-URL: #40344 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent bcd59d7 commit a672be5
Copy full SHA for a672be5

File tree

Expand file treeCollapse file tree

3 files changed

+70
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+70
-0
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const {
3030
NumberIsNaN,
3131
NumberParseInt,
3232
ObjectDefineProperty,
33+
ObjectKeys,
3334
ObjectSetPrototypeOf,
3435
Symbol,
3536
} = primordials;
@@ -282,6 +283,20 @@ const kSetNoDelay = Symbol('kSetNoDelay');
282283

283284
function Socket(options) {
284285
if (!(this instanceof Socket)) return new Socket(options);
286+
const invalidKeys = [
287+
'objectMode',
288+
'readableObjectMode',
289+
'writableObjectMode',
290+
];
291+
invalidKeys.forEach((invalidKey) => {
292+
if (ObjectKeys(options).includes(invalidKey)) {
293+
throw new ERR_INVALID_ARG_VALUE(
294+
`options.${invalidKey}`,
295+
options[invalidKey],
296+
'is not supported'
297+
);
298+
}
299+
});
285300

286301
this.connecting = false;
287302
// Problem with this is that users can supply their own handle, that may not
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
6+
{
7+
const invalidKeys = [
8+
'objectMode',
9+
'readableObjectMode',
10+
'writableObjectMode',
11+
];
12+
invalidKeys.forEach((invalidKey) => {
13+
const option = {
14+
...common.localhostIPv4,
15+
[invalidKey]: true
16+
};
17+
const message = `The property 'options.${invalidKey}' is not supported. Received true`;
18+
19+
assert.throws(() => {
20+
net.createConnection(option);
21+
}, {
22+
code: 'ERR_INVALID_ARG_VALUE',
23+
name: 'TypeError',
24+
message: new RegExp(message)
25+
});
26+
});
27+
}
Collapse file
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
6+
{
7+
const invalidKeys = [
8+
'objectMode',
9+
'readableObjectMode',
10+
'writableObjectMode',
11+
];
12+
invalidKeys.forEach((invalidKey) => {
13+
const option = {
14+
...common.localhostIPv4,
15+
[invalidKey]: true
16+
};
17+
const message = `The property 'options.${invalidKey}' is not supported. Received true`;
18+
19+
assert.throws(() => {
20+
const socket = new net.Socket(option);
21+
socket.connect({ port: 8080 });
22+
}, {
23+
code: 'ERR_INVALID_ARG_VALUE',
24+
name: 'TypeError',
25+
message: new RegExp(message)
26+
});
27+
});
28+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.