File tree Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ describe('Core Functions / Pattern', () => {
18
18
expect ( await runPattern ( 'aBc' , { match : '/[abc]+/im' } ) ) . toEqual ( [ ] ) ;
19
19
} ) ;
20
20
21
+ it ( 'should return same results when given a global (g) marker (pattern cache usecase)' , async ( ) => {
22
+ expect ( await runPattern ( 'abc' , { match : '/[abc]+/gi' } ) ) . toEqual ( [ ] ) ;
23
+ expect ( await runPattern ( 'abc' , { match : '/[abc]+/gi' } ) ) . toEqual ( [ ] ) ;
24
+ expect ( await runPattern ( 'abc' , { match : '/[abc]+/gi' } ) ) . toEqual ( [ ] ) ;
25
+ } ) ;
26
+
21
27
it ( 'given string regex containing invalid flags, should throw an exception' , async ( ) => {
22
28
await expect ( runPattern ( 'aBc' , { match : '/[abc]+/invalid' } ) ) . rejects . toThrow (
23
29
"Invalid flags supplied to RegExp constructor 'invalid'" ,
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ const cache = new Map<string, RegExp>();
27
27
function getFromCache ( pattern : string ) : RegExp {
28
28
const existingPattern = cache . get ( pattern ) ;
29
29
if ( existingPattern !== void 0 ) {
30
+ existingPattern . lastIndex = 0 ;
30
31
return existingPattern ;
31
32
}
32
33
You can’t perform that action at this time.
0 commit comments