Skip to content

Commit

Permalink
Fixed issue with recursion and passing strings into objects.
Browse files Browse the repository at this point in the history
I stumbled upon a bug in when using this merge method directly to merge two query param objects with each other containing only string values. 

e.g, target as {userId: "1234"} source as {userId: "64321"}.

This recursively caused the logic for passing strings into objects kick in as follows:
Target = "1234", Source = "64321".
"1234"["64321"] = true;

Hence the modified else clause to be sure that target is an object and not a string.

Regards
Per
  • Loading branch information
1313 committed Feb 13, 2015
1 parent 9250c4c commit dbc28d0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports.merge = function (target, source) {
if (Array.isArray(target)) {
target.push(source);
}
else {
else if (typeof target !== 'object') {
target[source] = true;
}

Expand Down

0 comments on commit dbc28d0

Please sign in to comment.