File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ var isWin32 = require('os').platform() === 'win32';
66
77var slash = '/' ;
88var backslash = / \\ / g;
9- var enclosure = / [ { [ ] .* \/ .* [ } \] ] $ / ;
109var globby = / ( ^ | [ ^ \\ ] ) ( [ { [ ] | \( [ ^ ) ] + $ ) / ;
1110var escaped = / \\ ( [ ! * ? | [ \] ( ) { } ] ) / g;
1211
@@ -24,7 +23,7 @@ module.exports = function globParent(str, opts) {
2423 }
2524
2625 // special case for strings ending in enclosure containing path separator
27- if ( enclosure . test ( str ) ) {
26+ if ( isEnclosure ( str ) ) {
2827 str += slash ;
2928 }
3029
@@ -39,3 +38,27 @@ module.exports = function globParent(str, opts) {
3938 // remove escape chars and return result
4039 return str . replace ( escaped , '$1' ) ;
4140} ;
41+
42+
43+ function isEnclosure ( str ) {
44+ var lastChar = str . slice ( - 1 )
45+
46+ var enclosureStart ;
47+ switch ( lastChar ) {
48+ case '}' :
49+ enclosureStart = '{' ;
50+ break ;
51+ case ']' :
52+ enclosureStart = '[' ;
53+ break ;
54+ default :
55+ return false ;
56+ }
57+
58+ var foundIndex = str . indexOf ( enclosureStart ) ;
59+ if ( foundIndex < 0 ) {
60+ return false ;
61+ }
62+
63+ return str . slice ( foundIndex + 1 , - 1 ) . includes ( slash ) ;
64+ }
Original file line number Diff line number Diff line change @@ -224,6 +224,24 @@ describe('glob2base test patterns', function () {
224224
225225 done ( ) ;
226226 } ) ;
227+
228+ it ( 'should finish in reasonable time for \'{\' + \'/\'.repeat(n) [CVE-2021-35065]' , function ( done ) {
229+ this . timeout ( 1000 ) ;
230+ gp ( '{' + '/' . repeat ( 500000 ) ) ;
231+ done ( ) ;
232+ } ) ;
233+
234+ it ( 'should finish in reasonable time for \'{\'.repeat(n)' , function ( done ) {
235+ this . timeout ( 1000 ) ;
236+ gp ( '{' . repeat ( 500000 ) ) ;
237+ done ( ) ;
238+ } ) ;
239+
240+ it ( 'should finish in reasonable time for \'(\'.repeat(n)' , function ( done ) {
241+ this . timeout ( 1000 ) ;
242+ gp ( '(' . repeat ( 500000 ) ) ;
243+ done ( ) ;
244+ } ) ;
227245} ) ;
228246
229247if ( isWin32 ) {
You can’t perform that action at this time.
0 commit comments