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

Non-integers treated as valid indices for created arrays #11

Closed
Andarist opened this issue Sep 7, 2018 · 3 comments
Closed

Non-integers treated as valid indices for created arrays #11

Andarist opened this issue Sep 7, 2018 · 3 comments

Comments

@Andarist
Copy link

Andarist commented Sep 7, 2018

var obj = {}
dset(obj, ['foo', '10.2', 'baz'], 'bar')

Produces an array with 10.2 property.

@lukeed
Copy link
Owner

lukeed commented Sep 7, 2018

What would you expect it to be? This is the same result as 1.x branch. If you pass an array of keys (instead of dot-notation), it accepts each item as is, which is ideal for pre-formatting keys instead of risking hello.world to be split up for whatever reason.

@Andarist
Copy link
Author

Andarist commented Sep 8, 2018

Array.isArray(obj.foo)
// dset@2 - true
// dset@1 - false
// _.set - false
// R.assocPath - false

I didn't expect the key to be split, but rather that non-integer (non-positive) would not create an array.

@lukeed
Copy link
Owner

lukeed commented Sep 8, 2018

I see it now 😄 Bug with tape.js actually, I think

foo = {};
fn(foo, ['x', '10.2', 'z'], 123);
t.same(foo, { x:{ '10.2':{ z:123 } } });

^ Passed, despite the result being an array as you've pointed out.

@lukeed lukeed closed this as completed in 2b9ec49 Sep 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants