Skip to content

Make setIn write to out-of-bounds array indices #34

@ditkin

Description

@ditkin

Running into bug where using setIn to write to out-of-bounds array indices just pushes to array instead.

Code: setIn([2], 'abc', [])
Expected: [empty, empty, 'abc']
Actual: ['abc']

The cause is the use of splice() in _set when dealing with Arrays. Splice doesn’t let you write past the end of an array.

Solution:
instead of using splice we can use next[index] = value, which will fill the array with empty to ensure we write to correct index.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions