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

Commit 122ab07

Browse files
fix(angular.copy): support copying XML nodes
Closes #5429 Closes #12786
1 parent e22bf9a commit 122ab07

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Angular.js

+2
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ function copy(source, destination, stackSource, stackDest) {
825825
} else if (isRegExp(source)) {
826826
destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
827827
destination.lastIndex = source.lastIndex;
828+
} else if (isFunction(source.cloneNode)) {
829+
destination = source.cloneNode(true);
828830
} else {
829831
var emptyObject = Object.create(getPrototypeOf(source));
830832
return copy(source, emptyObject, stackSource, stackDest);

test/AngularSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,18 @@ describe('angular', function() {
386386
expect(aCopy).toBe(aCopy.self);
387387
});
388388

389+
it('should deeply copy XML nodes', function() {
390+
var anElement = document.createElement('foo');
391+
anElement.appendChild(document.createElement('bar'));
392+
var theCopy = anElement.cloneNode(true);
393+
expect(copy(anElement).outerHTML).toEqual(theCopy.outerHTML);
394+
expect(copy(anElement)).not.toBe(anElement);
395+
});
396+
397+
it('should not try to call a non-function called `cloneNode`', function() {
398+
expect(copy.bind(null, { cloneNode: 100 })).not.toThrow();
399+
});
400+
389401
it('should handle objects with multiple references', function() {
390402
var b = {};
391403
var a = [b, -1, b];

0 commit comments

Comments
 (0)