Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(copy): clear array destinations correctly for non-array sources #8702

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Aug 21, 2014

Previously, we failed to modify the length property of an array destination when
dealing with non-array sources. This CL ensures that the length is correctly reset
to 0 before copying properties from the source object.

While it's not a super-important feature, it's literally a single line of code and
not very difficult to understand

Closes #8610

@caitp caitp added this to the 1.3.0 milestone Aug 21, 2014
@@ -803,6 +803,7 @@ function copy(source, destination, stackSource, stackDest) {
forEach(destination, function(value, key) {
delete destination[key];
});
if (isArray(destination)) destination.length = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you move the forEach above into an else branch here?

@IgorMinar
Copy link
Contributor

otherwise LGTM

@caitp caitp closed this in a603e20 Aug 21, 2014
@caitp
Copy link
Contributor Author

caitp commented Aug 21, 2014

change made and merged, thanks for the prompt review!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

angular.copy return [undefined] when copy undefined to array
2 participants