File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -533,6 +533,9 @@ class Minimatch {
533533 continue
534534 }
535535
536+ // coalesce consecutive non-globstar * characters
537+ if ( c === '*' && stateChar === '*' ) continue
538+
536539 // if we already have a stateChar, then it means
537540 // that there was something like ** or +? in there.
538541 // Handle the stateChar, then proceed with this one.
Original file line number Diff line number Diff line change 1+ const tap = require ( 'tap' )
2+ const { Minimatch } = require ( '../' )
3+
4+ tap . test ( 'consecutive stars are coalesced' , t => {
5+ const re1 = new Minimatch ( 'a*b' ) . makeRe ( )
6+ const re3 = new Minimatch ( 'a***b' ) . makeRe ( )
7+ t . equal ( re3 . toString ( ) , re1 . toString ( ) , 'a***b same regex as a*b' )
8+ t . end ( )
9+ } )
10+
11+ tap . test ( '100+ consecutive stars do not cause ReDoS' , t => {
12+ const stars = '*' . repeat ( 100 )
13+ const pattern = 'a' + stars + 'b'
14+ const start = Date . now ( )
15+ const mm = new Minimatch ( pattern )
16+ const re = mm . makeRe ( )
17+ re . test ( 'a' + 'c' . repeat ( 25 ) )
18+ const elapsed = Date . now ( ) - start
19+ t . ok ( elapsed < 1000 , 'completed in ' + elapsed + 'ms (< 1s)' )
20+ t . end ( )
21+ } )
You can’t perform that action at this time.
0 commit comments