Repository navigation
Conversation
…ith undefined baseClone's array loop iterated every index from 0 to length-1 and always called assignValue, so indices with no own property (array holes) were written as an explicit undefined on the clone. That diverges from structuredClone, which leaves holes untouched. Skip indices that are not own properties of the source array so the new array keeps the same holes as the original. Fixes lodash#6191
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6191
_.cloneDeep on a sparse array currently fills every hole with an explicit undefined instead of leaving it empty, which diverges from native structuredClone.
The array branch in baseClone iterates every index from 0 to length-1 and always calls assignValue, even when the source has no own property at that index. Skipping indices that are not own properties of the source keeps the clone's holes matching the original.
Repro from the issue:
Added a regression test alongside the existing clone/cloneDeep tests. Ran the full suite locally (npm test), 6834/6834 passing, and jscs style checks clean on both lodash.js and test/test.js.
Scoped this to cloneDeep since that's what #6191 reports. _.clone (shallow) has the same underlying gap via copyArray, happy to follow up separately if that's wanted.