Skip to content

Commit 3c5812e

Browse files
committed
JS: Avoid side effects on object passed to r.connect
(The true author of this is @marshall007 in a comment in PR 6135.)
1 parent 9a2b3df commit 3c5812e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,11 +1630,14 @@ module.exports.connect = varar 0, 2, (hostOrCallback, callback) ->
16301630
# and set host to an empty object
16311631
host = {}
16321632
callback = hostOrCallback
1633-
else
1633+
else if typeof hostOrCallback is 'string'
16341634
# Otherwise, the `callback` variable is already correctly
16351635
# holding the callback, and the host variable is the first
1636-
# argument
1637-
host = hostOrCallback || {}
1636+
# argument -- either a string or an object.
1637+
host = hostOrCallback
1638+
else
1639+
# Copy the object so that we feel free to modify it.
1640+
host = Object.assign {}, hostOrCallback
16381641

16391642
# `r.connect` returns a Promise which does the following:
16401643
#

0 commit comments

Comments
 (0)