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

fix(copy) $resource throws TypeError when json has both properties & arrays #2255

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ function copy(source, destination){
}
} else {
if (source === destination) throw Error("Can't copy equivalent objects or arrays");
if (isArray(source)) {
if (isArray(source) && isArray(destination)) {
destination.length = 0;
for ( var i = 0; i < source.length; i++) {
destination.push(copy(source[i]));
Expand Down
6 changes: 6 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ describe('angular', function() {
expect(copy([{key:null}])).toEqual([{key:null}]);
});

it("should copy an object with properities and arrays", function() {
var src = {name:"value", "array1": [ {"p1": "v1"}, {"p2": "v2"} ]};
var dst = copy(src);
expect(dst).toEqual(src);
});

it('should throw an exception if a Scope is being copied', inject(function($rootScope) {
expect(function() { copy($rootScope.$new()); }).toThrow("Can't copy Window or Scope");
}));
Expand Down