You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a bug with handling numeric object keys within arrays.
This occurs when you convert an object with such keys into dot notation and attempt to convert it back to an object.
Notice that the object { "6": "number six" } is converted to an array where 6 is the array index.
Found a fix
I investigated the issue and found that the issue is with the isIndex method in the index.js since it parses all digits as array indexes.
My fix was to pad array indexes with "⁈" and "⁉" so that the path generated by parsePath looks like arr/⁈0⁉/6 and not arr/0/6 which differentiates the numeric object key and array index.
functionparsePath(path,sep){// in the event one should have "⁈" in their keysif(path.indexOf('⁈')>=0){path=path.replace(/⁈/g,'⁈⁈');}// in the event one should have "⁉" in their keysif(path.indexOf('⁉')>=0){path=path.replace(/⁉/g,'⁉⁉');}// pad array indexes with "⁈" and "⁉" so that 0=>"⁈0⁉"if(path.indexOf('[')>=0){path=path.replace(/\[/g,sep+'⁈').replace(/]/g,'⁉');}varparts=path.split(sep)varcheck=parts.filter(blacklistFilter)if(check.length!==parts.length){throwError('Refusing to update blacklisted property '+path)}returnparts}
This means that we now check for indexes as shown below:
functionisIndex(k){return/^⁈\d+⁉$/.test(k)}
And finally, to avoid spitting out ⁈0⁉ in objects I added a regex to remove the index padding so that _.fill method now starts with:
I'm not sure if there is a better fix for this issue so I'm raising an issue as well as contributing my solution to get the conversation started.
If this is the best solution, then I'm ready to submit a PR.
The text was updated successfully, but these errors were encountered:
I found a bug with handling numeric object keys within arrays.
This occurs when you convert an object with such keys into dot notation and attempt to convert it back to an object.
Here is code to demonstrate what I mean:
This will log the following:
Notice that the object
{ "6": "number six" }
is converted to an array where6
is the array index.Found a fix
I investigated the issue and found that the issue is with the
isIndex
method in the index.js since it parses all digits as array indexes.My fix was to pad array indexes with "⁈" and "⁉" so that the path generated by parsePath looks like
arr/⁈0⁉/6
and notarr/0/6
which differentiates the numeric object key and array index.This means that we now check for indexes as shown below:
And finally, to avoid spitting out
⁈0⁉
in objects I added a regex to remove the index padding so that _.fill method now starts with:Results
This might be too 'hacky'
I'm not sure if there is a better fix for this issue so I'm raising an issue as well as contributing my solution to get the conversation started.
If this is the best solution, then I'm ready to submit a PR.
The text was updated successfully, but these errors were encountered: