File tree 2 files changed +7
-1
lines changed 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -583,7 +583,7 @@ function copy(source, destination){
583
583
}
584
584
} else {
585
585
if ( source === destination ) throw Error ( "Can't copy equivalent objects or arrays" ) ;
586
- if ( isArray ( source ) ) {
586
+ if ( isArray ( source ) && isArray ( destination ) ) {
587
587
destination . length = 0 ;
588
588
for ( var i = 0 ; i < source . length ; i ++ ) {
589
589
destination . push ( copy ( source [ i ] ) ) ;
Original file line number Diff line number Diff line change @@ -83,6 +83,12 @@ describe('angular', function() {
83
83
expect ( copy ( [ { key :null } ] ) ) . toEqual ( [ { key :null } ] ) ;
84
84
} ) ;
85
85
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
+
86
92
it ( 'should throw an exception if a Scope is being copied' , inject ( function ( $rootScope ) {
87
93
expect ( function ( ) { copy ( $rootScope . $new ( ) ) ; } ) . toThrow ( "Can't copy Window or Scope" ) ;
88
94
} ) ) ;
You can’t perform that action at this time.
0 commit comments