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

Commit

Permalink
fix(angular.copy): support copying XML nodes
Browse files Browse the repository at this point in the history
Closes #5429
  • Loading branch information
petebacondarwin committed Sep 8, 2015
1 parent 80a2176 commit df0921c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ function copy(source, destination, stackSource, stackDest) {
} else if (isRegExp(source)) {
destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
destination.lastIndex = source.lastIndex;
} else if (source.cloneNode) {
destination = source.cloneNode();
} else {
var emptyObject = Object.create(getPrototypeOf(source));
return copy(source, emptyObject, stackSource, stackDest);
Expand Down
7 changes: 7 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ describe('angular', function() {
expect(aCopy).toBe(aCopy.self);
});

it("should support XML nodes", function() {
var anElement = document.createElement("foo");
var theCopy = anElement.cloneNode();
expect(copy(anElement).outerHTML).toEqual(theCopy.outerHTML);
expect(copy(anElement)).not.toBe(anElement);
});

it('should handle objects with multiple references', function() {
var b = {};
var a = [b, -1, b];
Expand Down

0 comments on commit df0921c

Please sign in to comment.