File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff 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
283284function 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
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