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

Commit

Permalink
fix(merge): regExp should not be treated as a objects when merging.
Browse files Browse the repository at this point in the history
angular.merge({ key: /regexp/ }) now works the way you'd expect it to.

Horray!

Closes #12419
Closes #12409
  • Loading branch information
sreeramu authored and caitp committed Jul 24, 2015
1 parent 18a2e4f commit a5221f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Angular.js
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/AngularSpec.js
Expand Up @@ -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)).toBe(true);
expect(dst.regexp.toString()).toBe(src.regexp.toString());
});
});


Expand Down

0 comments on commit a5221f3

Please sign in to comment.