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

Commit 86340a5

Browse files
shahatapetebacondarwin
authored andcommittedJul 25, 2014
fix(angular.copy): clone regexp flags correctly
Closes #5781 Closes #8337
1 parent c03b9e5 commit 86340a5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎src/Angular.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,8 @@ function copy(source, destination, stackSource, stackDest) {
775775
} else if (isDate(source)) {
776776
destination = new Date(source.getTime());
777777
} else if (isRegExp(source)) {
778-
destination = new RegExp(source.source);
778+
destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
779+
destination.lastIndex = source.lastIndex;
779780
} else if (isObject(source)) {
780781
var emptyObject = Object.create(Object.getPrototypeOf(source));
781782
destination = copy(source, emptyObject, stackSource, stackDest);

‎test/AngularSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ describe('angular', function() {
5555
expect(copy(re) === re).toBeFalsy();
5656
});
5757

58+
it("should copy RegExp with flags", function() {
59+
var re = new RegExp('.*', 'gim');
60+
expect(copy(re).global).toBe(true);
61+
expect(copy(re).ignoreCase).toBe(true);
62+
expect(copy(re).multiline).toBe(true);
63+
});
64+
65+
it("should copy RegExp with lastIndex", function() {
66+
var re = /a+b+/g;
67+
var str = 'ab aabb';
68+
expect(re.exec(str)[0]).toEqual('ab');
69+
expect(copy(re).exec(str)[0]).toEqual('aabb');
70+
});
71+
5872
it("should deeply copy literal RegExp", function() {
5973
var objWithRegExp = {
6074
re: /.*/

0 commit comments

Comments
 (0)
This repository has been archived.