@@ -8978,10 +8978,10 @@ exports.isPlainObject = isPlainObject;
8978
8978
module.exports = minimatch
8979
8979
minimatch.Minimatch = Minimatch
8980
8980
8981
- var path = { sep: '/' }
8982
- try {
8983
- path = __nccwpck_require__(1017)
8984
- } catch (er) {}
8981
+ var path = (function () { try { return __nccwpck_require__(1017) } catch (e) {}}()) || {
8982
+ sep: '/'
8983
+ }
8984
+ minimatch.sep = path.sep
8985
8985
8986
8986
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
8987
8987
var expand = __nccwpck_require__(3717)
@@ -9033,43 +9033,64 @@ function filter (pattern, options) {
9033
9033
}
9034
9034
9035
9035
function ext (a, b) {
9036
- a = a || {}
9037
9036
b = b || {}
9038
9037
var t = {}
9039
- Object.keys(b).forEach(function (k) {
9040
- t[k] = b[k]
9041
- })
9042
9038
Object.keys(a).forEach(function (k) {
9043
9039
t[k] = a[k]
9044
9040
})
9041
+ Object.keys(b).forEach(function (k) {
9042
+ t[k] = b[k]
9043
+ })
9045
9044
return t
9046
9045
}
9047
9046
9048
9047
minimatch.defaults = function (def) {
9049
- if (!def || !Object.keys(def).length) return minimatch
9048
+ if (!def || typeof def !== 'object' || !Object.keys(def).length) {
9049
+ return minimatch
9050
+ }
9050
9051
9051
9052
var orig = minimatch
9052
9053
9053
9054
var m = function minimatch (p, pattern, options) {
9054
- return orig.minimatch (p, pattern, ext(def, options))
9055
+ return orig(p, pattern, ext(def, options))
9055
9056
}
9056
9057
9057
9058
m.Minimatch = function Minimatch (pattern, options) {
9058
9059
return new orig.Minimatch(pattern, ext(def, options))
9059
9060
}
9061
+ m.Minimatch.defaults = function defaults (options) {
9062
+ return orig.defaults(ext(def, options)).Minimatch
9063
+ }
9064
+
9065
+ m.filter = function filter (pattern, options) {
9066
+ return orig.filter(pattern, ext(def, options))
9067
+ }
9068
+
9069
+ m.defaults = function defaults (options) {
9070
+ return orig.defaults(ext(def, options))
9071
+ }
9072
+
9073
+ m.makeRe = function makeRe (pattern, options) {
9074
+ return orig.makeRe(pattern, ext(def, options))
9075
+ }
9076
+
9077
+ m.braceExpand = function braceExpand (pattern, options) {
9078
+ return orig.braceExpand(pattern, ext(def, options))
9079
+ }
9080
+
9081
+ m.match = function (list, pattern, options) {
9082
+ return orig.match(list, pattern, ext(def, options))
9083
+ }
9060
9084
9061
9085
return m
9062
9086
}
9063
9087
9064
9088
Minimatch.defaults = function (def) {
9065
- if (!def || !Object.keys(def).length) return Minimatch
9066
9089
return minimatch.defaults(def).Minimatch
9067
9090
}
9068
9091
9069
9092
function minimatch (p, pattern, options) {
9070
- if (typeof pattern !== 'string') {
9071
- throw new TypeError('glob pattern string required')
9072
- }
9093
+ assertValidPattern(pattern)
9073
9094
9074
9095
if (!options) options = {}
9075
9096
@@ -9078,9 +9099,6 @@ function minimatch (p, pattern, options) {
9078
9099
return false
9079
9100
}
9080
9101
9081
- // "" only matches ""
9082
- if (pattern.trim() === '') return p === ''
9083
-
9084
9102
return new Minimatch(pattern, options).match(p)
9085
9103
}
9086
9104
@@ -9089,15 +9107,14 @@ function Minimatch (pattern, options) {
9089
9107
return new Minimatch(pattern, options)
9090
9108
}
9091
9109
9092
- if (typeof pattern !== 'string') {
9093
- throw new TypeError('glob pattern string required')
9094
- }
9110
+ assertValidPattern(pattern)
9095
9111
9096
9112
if (!options) options = {}
9113
+
9097
9114
pattern = pattern.trim()
9098
9115
9099
9116
// windows support: need to use /, not \
9100
- if (path.sep !== '/') {
9117
+ if (!options.allowWindowsEscape && path.sep !== '/') {
9101
9118
pattern = pattern.split(path.sep).join('/')
9102
9119
}
9103
9120
@@ -9108,6 +9125,7 @@ function Minimatch (pattern, options) {
9108
9125
this.negate = false
9109
9126
this.comment = false
9110
9127
this.empty = false
9128
+ this.partial = !!options.partial
9111
9129
9112
9130
// make the set of regexps etc.
9113
9131
this.make()
@@ -9117,9 +9135,6 @@ Minimatch.prototype.debug = function () {}
9117
9135
9118
9136
Minimatch.prototype.make = make
9119
9137
function make () {
9120
- // don't do it more than once.
9121
- if (this._made) return
9122
-
9123
9138
var pattern = this.pattern
9124
9139
var options = this.options
9125
9140
@@ -9139,7 +9154,7 @@ function make () {
9139
9154
// step 2: expand braces
9140
9155
var set = this.globSet = this.braceExpand()
9141
9156
9142
- if (options.debug) this.debug = console.error
9157
+ if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }
9143
9158
9144
9159
this.debug(this.pattern, set)
9145
9160
@@ -9219,19 +9234,29 @@ function braceExpand (pattern, options) {
9219
9234
pattern = typeof pattern === 'undefined'
9220
9235
? this.pattern : pattern
9221
9236
9222
- if (typeof pattern === 'undefined') {
9223
- throw new TypeError('undefined pattern')
9224
- }
9237
+ assertValidPattern(pattern)
9225
9238
9226
- if (options.nobrace ||
9227
- !pattern.match(/\{.*\}/)) {
9239
+ // Thanks to Yeting Li <https://github.com/yetingli> for
9240
+ // improving this regexp to avoid a ReDOS vulnerability.
9241
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
9228
9242
// shortcut. no need to expand.
9229
9243
return [pattern]
9230
9244
}
9231
9245
9232
9246
return expand(pattern)
9233
9247
}
9234
9248
9249
+ var MAX_PATTERN_LENGTH = 1024 * 64
9250
+ var assertValidPattern = function (pattern) {
9251
+ if (typeof pattern !== 'string') {
9252
+ throw new TypeError('invalid pattern')
9253
+ }
9254
+
9255
+ if (pattern.length > MAX_PATTERN_LENGTH) {
9256
+ throw new TypeError('pattern is too long')
9257
+ }
9258
+ }
9259
+
9235
9260
// parse a component of the expanded set.
9236
9261
// At this point, no pattern may contain "/" in it
9237
9262
// so we're going to return a 2d array, where each entry is the full
@@ -9246,14 +9271,17 @@ function braceExpand (pattern, options) {
9246
9271
Minimatch.prototype.parse = parse
9247
9272
var SUBPARSE = {}
9248
9273
function parse (pattern, isSub) {
9249
- if (pattern.length > 1024 * 64) {
9250
- throw new TypeError('pattern is too long')
9251
- }
9274
+ assertValidPattern(pattern)
9252
9275
9253
9276
var options = this.options
9254
9277
9255
9278
// shortcuts
9256
- if (!options.noglobstar && pattern === '**') return GLOBSTAR
9279
+ if (pattern === '**') {
9280
+ if (!options.noglobstar)
9281
+ return GLOBSTAR
9282
+ else
9283
+ pattern = '*'
9284
+ }
9257
9285
if (pattern === '') return ''
9258
9286
9259
9287
var re = ''
@@ -9309,10 +9337,12 @@ function parse (pattern, isSub) {
9309
9337
}
9310
9338
9311
9339
switch (c) {
9312
- case '/':
9340
+ /* istanbul ignore next */
9341
+ case '/': {
9313
9342
// completely not allowed, even escaped.
9314
9343
// Should already be path-split by now.
9315
9344
return false
9345
+ }
9316
9346
9317
9347
case '\\':
9318
9348
clearStateChar()
@@ -9431,25 +9461,23 @@ function parse (pattern, isSub) {
9431
9461
9432
9462
// handle the case where we left a class open.
9433
9463
// "[z-a]" is valid, equivalent to "\[z-a\]"
9434
- if (inClass) {
9435
- // split where the last [ was, make sure we don't have
9436
- // an invalid re. if so, re-walk the contents of the
9437
- // would-be class to re-translate any characters that
9438
- // were passed through as-is
9439
- // TODO: It would probably be faster to determine this
9440
- // without a try/catch and a new RegExp, but it's tricky
9441
- // to do safely. For now, this is safe and works.
9442
- var cs = pattern.substring(classStart + 1, i)
9443
- try {
9444
- RegExp('[' + cs + ']')
9445
- } catch (er) {
9446
- // not a valid class!
9447
- var sp = this.parse(cs, SUBPARSE)
9448
- re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
9449
- hasMagic = hasMagic || sp[1]
9450
- inClass = false
9451
- continue
9452
- }
9464
+ // split where the last [ was, make sure we don't have
9465
+ // an invalid re. if so, re-walk the contents of the
9466
+ // would-be class to re-translate any characters that
9467
+ // were passed through as-is
9468
+ // TODO: It would probably be faster to determine this
9469
+ // without a try/catch and a new RegExp, but it's tricky
9470
+ // to do safely. For now, this is safe and works.
9471
+ var cs = pattern.substring(classStart + 1, i)
9472
+ try {
9473
+ RegExp('[' + cs + ']')
9474
+ } catch (er) {
9475
+ // not a valid class!
9476
+ var sp = this.parse(cs, SUBPARSE)
9477
+ re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
9478
+ hasMagic = hasMagic || sp[1]
9479
+ inClass = false
9480
+ continue
9453
9481
}
9454
9482
9455
9483
// finish up the class.
@@ -9533,9 +9561,7 @@ function parse (pattern, isSub) {
9533
9561
// something that could conceivably capture a dot
9534
9562
var addPatternStart = false
9535
9563
switch (re.charAt(0)) {
9536
- case '.':
9537
- case '[':
9538
- case '(': addPatternStart = true
9564
+ case '[': case '.': case '(': addPatternStart = true
9539
9565
}
9540
9566
9541
9567
// Hack to work around lack of negative lookbehind in JS
@@ -9597,7 +9623,7 @@ function parse (pattern, isSub) {
9597
9623
var flags = options.nocase ? 'i' : ''
9598
9624
try {
9599
9625
var regExp = new RegExp('^' + re + '$', flags)
9600
- } catch (er) {
9626
+ } catch (er) /* istanbul ignore next - should be impossible */ {
9601
9627
// If it was an invalid regular expression, then it can't match
9602
9628
// anything. This trick looks for a character after the end of
9603
9629
// the string, which is of course impossible, except in multi-line
@@ -9655,7 +9681,7 @@ function makeRe () {
9655
9681
9656
9682
try {
9657
9683
this.regexp = new RegExp(re, flags)
9658
- } catch (ex) {
9684
+ } catch (ex) /* istanbul ignore next - should be impossible */ {
9659
9685
this.regexp = false
9660
9686
}
9661
9687
return this.regexp
@@ -9673,8 +9699,8 @@ minimatch.match = function (list, pattern, options) {
9673
9699
return list
9674
9700
}
9675
9701
9676
- Minimatch.prototype.match = match
9677
- function match (f, partial) {
9702
+ Minimatch.prototype.match = function match (f, partial) {
9703
+ if (typeof partial === 'undefined') partial = this.partial
9678
9704
this.debug('match', f, this.pattern)
9679
9705
// short-circuit in the case of busted things.
9680
9706
// comments, etc.
@@ -9756,6 +9782,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
9756
9782
9757
9783
// should be impossible.
9758
9784
// some invalid regexp stuff in the set.
9785
+ /* istanbul ignore if */
9759
9786
if (p === false) return false
9760
9787
9761
9788
if (p === GLOBSTAR) {
@@ -9829,6 +9856,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
9829
9856
// no match was found.
9830
9857
// However, in partial mode, we can't say this is necessarily over.
9831
9858
// If there's more *pattern* left, then
9859
+ /* istanbul ignore if */
9832
9860
if (partial) {
9833
9861
// ran out of file
9834
9862
this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
@@ -9842,11 +9870,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
9842
9870
// patterns with magic have been turned into regexps.
9843
9871
var hit
9844
9872
if (typeof p === 'string') {
9845
- if (options.nocase) {
9846
- hit = f.toLowerCase() === p.toLowerCase()
9847
- } else {
9848
- hit = f === p
9849
- }
9873
+ hit = f === p
9850
9874
this.debug('string match', p, f, hit)
9851
9875
} else {
9852
9876
hit = f.match(p)
@@ -9877,16 +9901,16 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
9877
9901
// this is ok if we're doing the match as part of
9878
9902
// a glob fs traversal.
9879
9903
return partial
9880
- } else if (pi === pl) {
9904
+ } else /* istanbul ignore else */ if (pi === pl) {
9881
9905
// ran out of pattern, still have file left.
9882
9906
// this is only acceptable if we're on the very last
9883
9907
// empty segment of a file with a trailing slash.
9884
9908
// a/* should match a/b/
9885
- var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
9886
- return emptyFileEnd
9909
+ return (fi === fl - 1) && (file[fi] === '')
9887
9910
}
9888
9911
9889
9912
// should be unreachable.
9913
+ /* istanbul ignore next */
9890
9914
throw new Error('wtf?')
9891
9915
}
9892
9916
0 commit comments