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

Commit 233296a

Browse files
fix(angular.copy): support copying XML nodes
Closes #5429
1 parent 80a2176 commit 233296a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-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 (source.cloneNode) {
829+
destination = source.cloneNode();
828830
} else {
829831
var emptyObject = Object.create(getPrototypeOf(source));
830832
return copy(source, emptyObject, stackSource, stackDest);

test/AngularSpec.js

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

389+
it("should support XML nodes", function() {
390+
var anElement = document.createElement("foo");
391+
var theCopy = anElement.cloneNode();
392+
expect(copy(anElement.outerHTML)).toEqual(theCopy.outerHTML);
393+
expect(copy(anElement)).not.toBe(anElement);
394+
});
395+
389396
it('should handle objects with multiple references', function() {
390397
var b = {};
391398
var a = [b, -1, b];

0 commit comments

Comments
 (0)