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

Commit

Permalink
fix(merge): clone elements instead of treating them like simple objects
Browse files Browse the repository at this point in the history
	Similar fix to #11720

Closes #12286
  • Loading branch information
luckylooke authored and petebacondarwin committed Nov 2, 2015
1 parent de2a56b commit 838cf4b
Show file tree
Hide file tree
Showing 2 changed files with 28 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 @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});


Expand Down Expand Up @@ -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();
});
});


Expand Down

0 comments on commit 838cf4b

Please sign in to comment.