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

_.set does not work when Symbol is in path array #3189

Closed
Kefaise opened this issue Jun 6, 2017 · 3 comments
Closed

_.set does not work when Symbol is in path array #3189

Kefaise opened this issue Jun 6, 2017 · 3 comments
Labels

Comments

@Kefaise
Copy link

Kefaise commented Jun 6, 2017

Code to reproduce on lodash v4.17.4.

var symbol = Symbol('secret');
var path = ['path', 'to', symbol];
var obj = {};
_.set(obj, path, ['array', 'of', 'secret', 'values']);

Throws exception TypeError: Cannot convert a Symbol value to a string in regexp in isIndex function. It uses regexp to check if index is number as string, but unfortunately this value is not a string. From my brief analysis baseSet function checks if new value is Object, if not it assumes next path piece is either string or number and pass it to isIndex function to determine if new value should be array or sub object. I think it should have third check if path is symbol.

@Kefaise
Copy link
Author

Kefaise commented Jun 6, 2017

Workaround

var symbol = Symbol('secret');
var path = ['path', 'to'];
var obj = {};
_.set(obj, path, _.get(obj, path, {}));
_.set(obj, _.concat(path, [symbol]), ['array', 'of', 'secret', 'values']);

@jdalton jdalton added the bug label Jun 6, 2017
@jdalton jdalton closed this as completed in bacaaae Jun 6, 2017
@jdalton
Copy link
Member

jdalton commented Jun 6, 2017

Thanks @Kefaise!

@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.