Skip to content
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
@jpsimons

Description

@jpsimons

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions