Skip to content
Permalink
Browse files

fix(merge): clone elements instead of treating them like simple objects

	Similar fix to #11720

Closes #12286
  • Loading branch information...
luckylooke authored and petebacondarwin committed Jul 7, 2015
1 parent de2a56b commit 838cf4be3c671903796dbb69d95c0e5ac1516a06
Showing with 28 additions and 0 deletions.
  1. +2 −0 src/Angular.js
  2. +26 −0 test/AngularSpec.js
@@ -360,6 +360,8 @@ function baseExtend(dst, objs, deep) {
dst[key] = new Date(src.valueOf());
} else if (isRegExp(src)) {
dst[key] = new RegExp(src);
} else if (isElement(src)) {
dst[key] = src[0] ? jqLite(src).clone()[0] : jqLite(src).clone();
} else {
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
baseExtend(dst[key], [src], true);
@@ -522,6 +522,17 @@ describe('angular', function() {

expect(dst.date).toBe(src.date);
});

it('should copy elements by reference', function() {
var src = { element: document.createElement('div'),
jqObject: jqLite("<p><span>s1</span><span>s2</span></p>").find("span") };
var dst = {};

extend(dst, src);

expect(dst.element).toBe(src.element);
expect(dst.jqObject).toBe(src.jqObject);
});
});


@@ -612,6 +623,21 @@ describe('angular', function() {
expect(isRegExp(dst.regexp)).toBe(true);
expect(dst.regexp.toString()).toBe(src.regexp.toString());
});


it('should copy(clone) elements', function() {
var src = { element: document.createElement('div'),
jqObject: jqLite("<p><span>s1</span><span>s2</span></p>").find("span") };
var dst = {};

merge(dst, src);

expect(dst.element).not.toBe(src.element);
expect(dst.jqObject).not.toBe(src.jqObject);

expect(isElement(dst.element)).toBeTruthy();
expect(isElement(dst.jqObject)).toBeTruthy();
});
});


0 comments on commit 838cf4b

Please sign in to comment.
You can’t perform that action at this time.