fix(angular.copy): clone regexp flags correctly
Closes #5781 Closes #8337
This commit is contained in:
committed by
Peter Bacon Darwin
parent
cd6d21e78a
commit
e25ed0d48d
+2
-1
@@ -786,7 +786,8 @@ function copy(source, destination, stackSource, stackDest) {
|
||||
} else if (isDate(source)) {
|
||||
destination = new Date(source.getTime());
|
||||
} else if (isRegExp(source)) {
|
||||
destination = new RegExp(source.source);
|
||||
destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
|
||||
destination.lastIndex = source.lastIndex;
|
||||
} else if (isObject(source)) {
|
||||
destination = copy(source, {}, stackSource, stackDest);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,20 @@ describe('angular', function() {
|
||||
expect(copy(re) === re).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should copy RegExp with flags", function() {
|
||||
var re = new RegExp('.*', 'gim');
|
||||
expect(copy(re).global).toBe(true);
|
||||
expect(copy(re).ignoreCase).toBe(true);
|
||||
expect(copy(re).multiline).toBe(true);
|
||||
});
|
||||
|
||||
it("should copy RegExp with lastIndex", function() {
|
||||
var re = /a+b+/g;
|
||||
var str = 'ab aabb';
|
||||
expect(re.exec(str)[0]).toEqual('ab');
|
||||
expect(copy(re).exec(str)[0]).toEqual('aabb');
|
||||
});
|
||||
|
||||
it("should deeply copy literal RegExp", function() {
|
||||
var objWithRegExp = {
|
||||
re: /.*/
|
||||
|
||||
Reference in New Issue
Block a user