File tree 3 files changed +70
-0
lines changed
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const {
30
30
NumberIsNaN,
31
31
NumberParseInt,
32
32
ObjectDefineProperty,
33
+ ObjectKeys,
33
34
ObjectSetPrototypeOf,
34
35
Symbol,
35
36
} = primordials ;
@@ -282,6 +283,20 @@ const kSetNoDelay = Symbol('kSetNoDelay');
282
283
283
284
function Socket ( options ) {
284
285
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
+ } ) ;
285
300
286
301
this . connecting = false ;
287
302
// Problem with this is that users can supply their own handle, that may not
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments