Skip to content

Array support causing unexpected value manipulated #35

@jasperjn

Description

@jasperjn

Hi, there

Since our team recently upgraded set-value from v3 to v4, we found there's a severe problem dealing with numeric path.
before v4 paths are treated as properties, so it worked as expected like the following example
Screen Shot 2021-09-28 at 3 01 26 PM

but since array index supported in v4, path contains numbers that causes target object's value transformed into an array anyway, and all its properties are gone.
Screen Shot 2021-09-28 at 3 01 19 PM

the root cause might be on

set-value/index.js

Lines 148 to 150 in c574eb8

if (typeof next === 'number' && !Array.isArray(obj[key])) {
obj = obj[key] = [];
continue;

but the quandary is, how to determine a numeric path is tending to set value to an array index or an object property?

I made a codesandbox to reproduce this issue, versions switch is available on the left panel, please let me know if any further information is needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions