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

Commit 0f956b2

Browse files
fix(angular.copy): support copying XML nodes
Closes #5429 Closes #12786
1 parent 17eb3d7 commit 0f956b2

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
@@ -762,6 +762,8 @@ function copy(source, destination, stackSource, stackDest) {
762762
} else if (isRegExp(source)) {
763763
destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
764764
destination.lastIndex = source.lastIndex;
765+
} else if (isFunction(source.cloneNode)) {
766+
destination = source.cloneNode(true);
765767
} else {
766768
var emptyObject = Object.create(getPrototypeOf(source));
767769
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)