-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: check args in net.connect() and socket.connect() calls
Previously Node.js would handle empty `net.connect()` and `socket.connect()` call as if the user passed empty options object which doesn't really make sense. This was due to the fact that it uses the same `normalizeArgs` function as `.listen()` call where such call is perfectly fine. This will make it clear what is the problem with such call and how it can be resolved. It now throws `ERR_MISSING_ARGS` if no arguments were passed or neither `path` nor `port` is specified. Fixes: #33930 PR-URL: #34022 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com>
- Loading branch information
1 parent
b546a2b
commit 78ca61e
Showing
7 changed files
with
52 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
// Tests that net.connect() called without arguments throws ERR_MISSING_ARGS. | ||
|
||
assert.throws(() => { | ||
net.connect(); | ||
}, { | ||
code: 'ERR_MISSING_ARGS', | ||
message: 'The "options" or "port" or "path" argument must be specified', | ||
}); | ||
|
||
assert.throws(() => { | ||
new net.Socket().connect(); | ||
}, { | ||
code: 'ERR_MISSING_ARGS', | ||
message: 'The "options" or "port" or "path" argument must be specified', | ||
}); | ||
|
||
assert.throws(() => { | ||
net.connect({}); | ||
}, { | ||
code: 'ERR_MISSING_ARGS', | ||
message: 'The "options" or "port" or "path" argument must be specified', | ||
}); | ||
|
||
assert.throws(() => { | ||
new net.Socket().connect({}); | ||
}, { | ||
code: 'ERR_MISSING_ARGS', | ||
message: 'The "options" or "port" or "path" argument must be specified', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters