diff options
| -rw-r--r-- | src/Angular.js | 2 | ||||
| -rw-r--r-- | test/AngularSpec.js | 23 | 
2 files changed, 25 insertions, 0 deletions
| diff --git a/src/Angular.js b/src/Angular.js index 0a38b230..8fd77096 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -587,6 +587,8 @@ function copy(source, destination){          destination = copy(source, []);        } else if (isDate(source)) {          destination = new Date(source.getTime()); +      } else if (isRegExp(source)) { +        destination = new RegExp(source.source);        } else if (isObject(source)) {          destination = copy(source, {});        } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index a67eb8a6..5da22174 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -31,6 +31,29 @@ describe('angular', function() {        expect(copy(date) === date).toBeFalsy();      }); +    it("should copy RegExp", function() { +      var re = new RegExp(".*"); +      expect(copy(re) instanceof RegExp).toBeTruthy(); +      expect(copy(re).source).toBe(".*"); +      expect(copy(re) === re).toBe(false); +    }); + +    it("should copy literal RegExp", function() { +      var re = /.*/; +      expect(copy(re) instanceof RegExp).toBeTruthy(); +      expect(copy(re).source).toEqual(".*"); +      expect(copy(re) === re).toBeFalsy(); +    }); + +    it("should deeply copy literal RegExp", function() { +      var objWithRegExp = { +        re: /.*/ +      }; +      expect(copy(objWithRegExp).re instanceof RegExp).toBeTruthy(); +      expect(copy(objWithRegExp).re.source).toEqual(".*"); +      expect(copy(objWithRegExp.re) === objWithRegExp.re).toBeFalsy(); +    }); +      it("should deeply copy an array into an existing array", function() {        var src = [1, {name:"value"}];        var dst = [{key:"v"}]; | 
