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

fix(merge): regExp should not be treated as a objects when merging. #12419

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
@@ -354,6 +354,8 @@ function baseExtend(dst, objs, deep) {
if (deep && isObject(src)) {
if (isDate(src)) {
dst[key] = new Date(src.valueOf());
} else if (isRegExp(src)) {
dst[key] = new RegExp(src);
} else {
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
baseExtend(dst[key], [src], true);
11 changes: 11 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
@@ -570,6 +570,17 @@ describe('angular', function() {
expect(isDate(dst.date)).toBeTruthy();
expect(dst.date.valueOf()).toEqual(src.date.valueOf());
});

it('should copy regexp by value', function() {
var src = { regexp: /blah/ };
var dst = {};

merge(dst, src);

expect(dst.regexp).not.toBe(src.regexp);
expect(isRegExp(dst.regexp)).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(isRegExp(dst.regexp)).toBeTrue();

expect(dst.regexp.toString()).toBe(src.regexp.toString());
});
});