@@ -235,7 +235,7 @@ function braceExpand (pattern, options) {
235
235
? this . pattern : pattern
236
236
237
237
if ( typeof pattern === 'undefined' ) {
238
- throw new Error ( 'undefined pattern' )
238
+ throw new TypeError ( 'undefined pattern' )
239
239
}
240
240
241
241
if ( options . nobrace ||
@@ -261,6 +261,10 @@ function braceExpand (pattern, options) {
261
261
Minimatch . prototype . parse = parse
262
262
var SUBPARSE = { }
263
263
function parse ( pattern , isSub ) {
264
+ if ( pattern . length > 1024 * 64 ) {
265
+ throw new TypeError ( 'pattern is too long' )
266
+ }
267
+
264
268
var options = this . options
265
269
266
270
// shortcuts
@@ -518,7 +522,7 @@ function parse (pattern, isSub) {
518
522
for ( pl = patternListStack . pop ( ) ; pl ; pl = patternListStack . pop ( ) ) {
519
523
var tail = re . slice ( pl . reStart + 3 )
520
524
// maybe some even number of \, then maybe 1 \, followed by a |
521
- tail = tail . replace ( / ( (?: \\ { 2 } ) * ) ( \\ ? ) \| / g, function ( _ , $1 , $2 ) {
525
+ tail = tail . replace ( / ( (?: \\ { 2 } ) { 0 , 64 } ) ( \\ ? ) \| / g, function ( _ , $1 , $2 ) {
522
526
if ( ! $2 ) {
523
527
// the | isn't already escaped, so escape it.
524
528
$2 = '\\'
@@ -615,7 +619,15 @@ function parse (pattern, isSub) {
615
619
}
616
620
617
621
var flags = options . nocase ? 'i' : ''
618
- var regExp = new RegExp ( '^' + re + '$' , flags )
622
+ try {
623
+ var regExp = new RegExp ( '^' + re + '$' , flags )
624
+ } catch ( er ) {
625
+ // If it was an invalid regular expression, then it can't match
626
+ // anything. This trick looks for a character after the end of
627
+ // the string, which is of course impossible, except in multi-line
628
+ // mode, but it's not a /m regex.
629
+ return new RegExp ( '$.' )
630
+ }
619
631
620
632
regExp . _glob = pattern
621
633
regExp . _src = re
0 commit comments