From a3a61e525b581971b195d8676467639b32476f57 Mon Sep 17 00:00:00 2001 From: Sreenivasan K Date: Thu, 23 Jul 2015 14:45:55 +0800 Subject: [PATCH] fix(merge): regExp should not be treated as a objects when merging. --- src/Angular.js | 2 ++ test/AngularSpec.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Angular.js b/src/Angular.js index 9d351a869bb0..bd5a5e72bec4 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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); diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 95269f7f38f5..4535bdcaf06c 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -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(); + expect(dst.regexp.toString()).toBe(src.regexp.toString()); + }); });