Skip to content

Commit 7641610

Browse files
committed
fix(copy) $resource throws TypeError when json has both properties and arrays
Closes angular#1044
1 parent 364e597 commit 7641610

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Angular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ function copy(source, destination){
583583
}
584584
} else {
585585
if (source === destination) throw Error("Can't copy equivalent objects or arrays");
586-
if (isArray(source)) {
586+
if (isArray(source) && isArray(destination)) {
587587
destination.length = 0;
588588
for ( var i = 0; i < source.length; i++) {
589589
destination.push(copy(source[i]));

test/AngularSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ describe('angular', function() {
8383
expect(copy([{key:null}])).toEqual([{key:null}]);
8484
});
8585

86+
it("should copy an object with properities and arrays", function() {
87+
var src = {name:"value", "array1": [ {"p1": "v1"}, {"p2": "v2"} ]};
88+
var dst = copy(src);
89+
expect(dst).toEqual(src);
90+
});
91+
8692
it('should throw an exception if a Scope is being copied', inject(function($rootScope) {
8793
expect(function() { copy($rootScope.$new()); }).toThrow("Can't copy Window or Scope");
8894
}));

0 commit comments

Comments
 (0)