https: prevent options object from being mutated

Previously, when passing options object to the agent.createConnection
method, the same options object got modified within the method. Now,
any modification will happen on only a copy of the object.

Fixes: https://github.com/nodejs/node/issues/31119

PR-URL: https://github.com/nodejs/node/pull/31151
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Vighnesh Raut
2020-01-02 08:42:19 +05:30
committed by Rich Trott
parent f64842adeb
commit fa946983cc
2 changed files with 27 additions and 1 deletions

View File

@@ -95,9 +95,11 @@ function createConnection(port, host, options) {
if (port !== null && typeof port === 'object') {
options = port;
} else if (host !== null && typeof host === 'object') {
options = host;
options = { ...host };
} else if (options === null || typeof options !== 'object') {
options = {};
} else {
options = { ...options };
}
if (typeof port === 'number') {