File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const {
35
35
NumberParseInt,
36
36
ObjectDefineProperty,
37
37
ObjectSetPrototypeOf,
38
+ RegExpPrototypeExec,
38
39
Symbol,
39
40
SymbolAsyncDispose,
40
41
SymbolDispose,
@@ -2019,6 +2020,10 @@ Server.prototype.listen = function(...args) {
2019
2020
toNumber ( args . length > 2 && args [ 2 ] ) ; // (port, host, backlog)
2020
2021
2021
2022
options = options . _handle || options . handle || options ;
2023
+ if ( typeof options . host === 'string' && RegExpPrototypeExec ( / \[ .* \] / , options . host ) !== null ) {
2024
+ throw new ERR_INVALID_ARG_VALUE ( 'host' , options . host , 'must not contain square brackets' ) ;
2025
+ }
2026
+
2022
2027
const flags = getFlags ( options . ipv6Only ) ;
2023
2028
// Refresh the id to make the previous call invalid
2024
2029
this . _listeningId ++ ;
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ const listenOnPort = [
66
66
name : 'TypeError' ,
67
67
message : / ^ T h e a r g u m e n t ' o p t i o n s ' m u s t h a v e t h e p r o p e r t y " p o r t " o r " p a t h " \. R e c e i v e d .+ $ / ,
68
68
} ) ;
69
+ } else if ( options . host && options . host . match ( / \[ .* \] / ) ) {
70
+ assert . throws ( fn ,
71
+ {
72
+ code : 'ERR_INVALID_ARG_VALUE' ,
73
+ name : 'TypeError' ,
74
+ message : / ^ T h e a r g u m e n t ' h o s t ' m u s t n o t c o n t a i n s q u a r e b r a c k e t s \. R e c e i v e d .+ $ / ,
75
+ } ) ;
69
76
} else {
70
77
assert . throws ( fn ,
71
78
{
@@ -91,4 +98,5 @@ const listenOnPort = [
91
98
shouldFailToListen ( { host : 'localhost:3000' } ) ;
92
99
shouldFailToListen ( { host : { port : 3000 } } ) ;
93
100
shouldFailToListen ( { exclusive : true } ) ;
101
+ shouldFailToListen ( { host : '[::]' , port : 3000 } ) ;
94
102
}
You can’t perform that action at this time.
0 commit comments