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

Commit 08029c7

Browse files
dmanekIgorMinar
authored andcommitted
fix(angular.copy): throw Error if source and destination are identical
Closes #693
1 parent 0bf6110 commit 08029c7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Angular.js

+1
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ function copy(source, destination){
597597
}
598598
}
599599
} else {
600+
if (source === destination) throw Error("Can't copy equivalent objects or arrays");
600601
if (isArray(source)) {
601602
while(destination.length) {
602603
destination.pop();

test/AngularSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ describe('angular', function() {
6565
it('should throw an exception if a Window is being copied', function() {
6666
expect(function() { copy(window); }).toThrow("Can't copy Window or Scope");
6767
});
68+
69+
it('should throw an exception when source and destination are equivalent', function() {
70+
var src, dst;
71+
src = dst = {key: 'value'};
72+
expect(function() { copy(src, dst); }).toThrow("Can't copy equivalent objects or arrays");
73+
src = dst = [2, 4];
74+
expect(function() { copy(src, dst); }).toThrow("Can't copy equivalent objects or arrays");
75+
});
6876
});
6977

7078
describe('equals', function() {

0 commit comments

Comments
 (0)