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
Closes #12786
  • Loading branch information
petebacondarwin committed Sep 9, 2015
1 parent e22bf9a commit 122ab07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Angular.js
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 (isFunction(source.cloneNode)) {
destination = source.cloneNode(true);
} else {
var emptyObject = Object.create(getPrototypeOf(source));
return copy(source, emptyObject, stackSource, stackDest);
Expand Down
12 changes: 12 additions & 0 deletions test/AngularSpec.js
Expand Up @@ -386,6 +386,18 @@ describe('angular', function() {
expect(aCopy).toBe(aCopy.self);
});

it('should deeply copy XML nodes', function() {
var anElement = document.createElement('foo');
anElement.appendChild(document.createElement('bar'));
var theCopy = anElement.cloneNode(true);
expect(copy(anElement).outerHTML).toEqual(theCopy.outerHTML);
expect(copy(anElement)).not.toBe(anElement);
});

it('should not try to call a non-function called `cloneNode`', function() {
expect(copy.bind(null, { cloneNode: 100 })).not.toThrow();
});

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

0 comments on commit 122ab07

Please sign in to comment.