From 233296a56fddbf1c093b6aaf5b59871afedb3b91 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Tue, 8 Sep 2015 13:52:44 +0100 Subject: [PATCH] fix(angular.copy): support copying XML nodes Closes #5429 --- src/Angular.js | 2 ++ test/AngularSpec.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/Angular.js b/src/Angular.js index 15d313d7b104..31070590e1b7 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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); diff --git a/test/AngularSpec.js b/test/AngularSpec.js index fd7f6e43bce3..794bc0af49f2 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -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];