This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
angular.copy should respect hasOwnProperty and not copy entire prototype chain #1427
Closed
Description
It's just a change on https://github.com/angular/angular.js/blob/master/src/Angular.js#L556 like:
- for ( var key in source) {
- destination[key] = copy(source[key]);
- }
+ for ( var key in source) {
+ if (source.hasOwnProperty(key)) {
+ destination[key] = copy(source[key]);
+ }
+ }
Can't think of any reason people would want the prototype chain treated as data...
We hit this issue in a couple of places, one we have "extended" ngResource objects with model-methods on them, and those get copied on $save. Not a problem until something references the DOM and it tries to copy the entire document.
Also when we open an edit dialog, we snapshot the current state of the data so that cancel would revert it. We do that using angular.copy and likewise, all the prototype methods get copied which breaks if the DOM is referenced somehow, with a stack overflow.
Metadata
Metadata
Assignees
Labels
No labels