Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@Kefaise

Description

@Kefaise

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions