Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple arguments overwrites values in arguments #18

Open
fiLLLip opened this issue Sep 27, 2019 · 4 comments
Open

Multiple arguments overwrites values in arguments #18

fiLLLip opened this issue Sep 27, 2019 · 4 comments
Labels

Comments

@fiLLLip
Copy link

fiLLLip commented Sep 27, 2019

Using Object.assign with an empty target, only the target is changed, not the inputs/arguments. Usign assign-deep, the inputs also get overwritten. Is this expected behaviour? I did not expect this.

var assignDeep = require("assign-deep")

var o1 = { a: 1, b: 1, c: {a: 1} };
var o2 = { b: 2, c: {a:2} };
var o3 = { c: {a:3} };

console.log(assignDeep({}, o1, o2, o3));
// Expected output: Object {a: 1, b: 2, c: Object {a: 3}}
console.log('o1', o1);
// Expected output: Object {a: 1, b: 1, c: Object {a: 1}}
// Actual output: Object {a: 1, b: 1, c: Object {a: 3}}

@fiLLLip
Copy link
Author

fiLLLip commented Sep 27, 2019

I found that also doing a Object.assign({}, o1) before piping into assignDeep didn't help, so maybe I'm in the wrong here. It's a "WAT" moment for me at least :)
To solve my use-case I created a method on top that deep copy the input values before piping into assignDeep, and that works for me.

@doowb doowb added the bug label Sep 27, 2019
@doowb
Copy link
Collaborator

doowb commented Sep 27, 2019

This looks like a bug to me. The code in this area should probably change, but I don't know off the top of my head what is necessary.

I'm not sure when I'll get a chance to look more closely, but PRs are welcome :)

@lisandro101
Copy link

same problem here, this didn't happen with version 0.4.8 or before.

@maiermic
Copy link

maiermic commented May 29, 2022

This looks like a bug to me. The code in this area should probably change, but I don't know off the top of my head what is necessary.

I'm not sure when I'll get a chance to look more closely, but PRs are welcome :)

This looks similar to this issue of a related project. I haven't tested it, but I guess, it can be fixed by changing the mentioned line

target[key] = args[i][key];
to

target[key] = assignSymbols({}, args[i][key]);

in case isObject(args[i][key]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants