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

Commit a5221f3

Browse files
sreeramucaitp
authored andcommitted
fix(merge): regExp should not be treated as a objects when merging.
angular.merge({ key: /regexp/ }) now works the way you'd expect it to. Horray! Closes #12419 Closes #12409
1 parent 18a2e4f commit a5221f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Angular.js

+2
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ function baseExtend(dst, objs, deep) {
354354
if (deep && isObject(src)) {
355355
if (isDate(src)) {
356356
dst[key] = new Date(src.valueOf());
357+
} else if (isRegExp(src)) {
358+
dst[key] = new RegExp(src);
357359
} else {
358360
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
359361
baseExtend(dst[key], [src], true);

test/AngularSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,17 @@ describe('angular', function() {
570570
expect(isDate(dst.date)).toBeTruthy();
571571
expect(dst.date.valueOf()).toEqual(src.date.valueOf());
572572
});
573+
574+
it('should copy regexp by value', function() {
575+
var src = { regexp: /blah/ };
576+
var dst = {};
577+
578+
merge(dst, src);
579+
580+
expect(dst.regexp).not.toBe(src.regexp);
581+
expect(isRegExp(dst.regexp)).toBe(true);
582+
expect(dst.regexp.toString()).toBe(src.regexp.toString());
583+
});
573584
});
574585

575586

0 commit comments

Comments
 (0)