set-value
set-value copied to clipboard
Array support causing unexpected value manipulated
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
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.
the root cause might be on https://github.com/jonschlinkert/set-value/blob/c574eb8d94ba21d22b6fe5a5741fd4dbfc9dc47a/index.js#L148-L150 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
@KVROHITH098 Hi, what did you mean it fixed? I opened the link you provided and the version is 3.x so it did work. but if you switch the version to 4.x it breaks!
I think the only way to sensibly handle arrays without breaking objects with numeric-string keys is to handle bracket notation like lodash does. eg a.b[0].c
@patrickfatrick Ditto, It should be more explicit than just turning everything into array with numeric keys.
I just experienced this issue during development. It was pretty surprising that the set-value call was deleting my data :|
At least an option to toggle this would be nice...