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';
6
6
7
7
var slash = '/' ;
8
8
var backslash = / \\ / g;
9
- var enclosure = / [ { [ ] .* \/ .* [ } \] ] $ / ;
10
9
var globby = / ( ^ | [ ^ \\ ] ) ( [ { [ ] | \( [ ^ ) ] + $ ) / ;
11
10
var escaped = / \\ ( [ ! * ? | [ \] ( ) { } ] ) / g;
12
11
@@ -24,7 +23,7 @@ module.exports = function globParent(str, opts) {
24
23
}
25
24
26
25
// special case for strings ending in enclosure containing path separator
27
- if ( enclosure . test ( str ) ) {
26
+ if ( isEnclosure ( str ) ) {
28
27
str += slash ;
29
28
}
30
29
@@ -39,3 +38,27 @@ module.exports = function globParent(str, opts) {
39
38
// remove escape chars and return result
40
39
return str . replace ( escaped , '$1' ) ;
41
40
} ;
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 () {
224
224
225
225
done ( ) ;
226
226
} ) ;
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
+ } ) ;
227
245
} ) ;
228
246
229
247
if ( isWin32 ) {
You can’t perform that action at this time.
0 commit comments