@@ -8978,10 +8978,10 @@ exports.isPlainObject = isPlainObject;
89788978module.exports = minimatch
89798979minimatch.Minimatch = Minimatch
89808980
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
89858985
89868986var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
89878987var expand = __nccwpck_require__(3717)
@@ -9033,43 +9033,64 @@ function filter (pattern, options) {
90339033}
90349034
90359035function ext (a, b) {
9036- a = a || {}
90379036 b = b || {}
90389037 var t = {}
9039- Object.keys(b).forEach(function (k) {
9040- t[k] = b[k]
9041- })
90429038 Object.keys(a).forEach(function (k) {
90439039 t[k] = a[k]
90449040 })
9041+ Object.keys(b).forEach(function (k) {
9042+ t[k] = b[k]
9043+ })
90459044 return t
90469045}
90479046
90489047minimatch.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+ }
90509051
90519052 var orig = minimatch
90529053
90539054 var m = function minimatch (p, pattern, options) {
9054- return orig.minimatch (p, pattern, ext(def, options))
9055+ return orig(p, pattern, ext(def, options))
90559056 }
90569057
90579058 m.Minimatch = function Minimatch (pattern, options) {
90589059 return new orig.Minimatch(pattern, ext(def, options))
90599060 }
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+ }
90609084
90619085 return m
90629086}
90639087
90649088Minimatch.defaults = function (def) {
9065- if (!def || !Object.keys(def).length) return Minimatch
90669089 return minimatch.defaults(def).Minimatch
90679090}
90689091
90699092function minimatch (p, pattern, options) {
9070- if (typeof pattern !== 'string') {
9071- throw new TypeError('glob pattern string required')
9072- }
9093+ assertValidPattern(pattern)
90739094
90749095 if (!options) options = {}
90759096
@@ -9078,9 +9099,6 @@ function minimatch (p, pattern, options) {
90789099 return false
90799100 }
90809101
9081- // "" only matches ""
9082- if (pattern.trim() === '') return p === ''
9083-
90849102 return new Minimatch(pattern, options).match(p)
90859103}
90869104
@@ -9089,15 +9107,14 @@ function Minimatch (pattern, options) {
90899107 return new Minimatch(pattern, options)
90909108 }
90919109
9092- if (typeof pattern !== 'string') {
9093- throw new TypeError('glob pattern string required')
9094- }
9110+ assertValidPattern(pattern)
90959111
90969112 if (!options) options = {}
9113+
90979114 pattern = pattern.trim()
90989115
90999116 // windows support: need to use /, not \
9100- if (path.sep !== '/') {
9117+ if (!options.allowWindowsEscape && path.sep !== '/') {
91019118 pattern = pattern.split(path.sep).join('/')
91029119 }
91039120
@@ -9108,6 +9125,7 @@ function Minimatch (pattern, options) {
91089125 this.negate = false
91099126 this.comment = false
91109127 this.empty = false
9128+ this.partial = !!options.partial
91119129
91129130 // make the set of regexps etc.
91139131 this.make()
@@ -9117,9 +9135,6 @@ Minimatch.prototype.debug = function () {}
91179135
91189136Minimatch.prototype.make = make
91199137function make () {
9120- // don't do it more than once.
9121- if (this._made) return
9122-
91239138 var pattern = this.pattern
91249139 var options = this.options
91259140
@@ -9139,7 +9154,7 @@ function make () {
91399154 // step 2: expand braces
91409155 var set = this.globSet = this.braceExpand()
91419156
9142- if (options.debug) this.debug = console.error
9157+ if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }
91439158
91449159 this.debug(this.pattern, set)
91459160
@@ -9219,19 +9234,29 @@ function braceExpand (pattern, options) {
92199234 pattern = typeof pattern === 'undefined'
92209235 ? this.pattern : pattern
92219236
9222- if (typeof pattern === 'undefined') {
9223- throw new TypeError('undefined pattern')
9224- }
9237+ assertValidPattern(pattern)
92259238
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)) {
92289242 // shortcut. no need to expand.
92299243 return [pattern]
92309244 }
92319245
92329246 return expand(pattern)
92339247}
92349248
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+
92359260// parse a component of the expanded set.
92369261// At this point, no pattern may contain "/" in it
92379262// so we're going to return a 2d array, where each entry is the full
@@ -9246,14 +9271,17 @@ function braceExpand (pattern, options) {
92469271Minimatch.prototype.parse = parse
92479272var SUBPARSE = {}
92489273function parse (pattern, isSub) {
9249- if (pattern.length > 1024 * 64) {
9250- throw new TypeError('pattern is too long')
9251- }
9274+ assertValidPattern(pattern)
92529275
92539276 var options = this.options
92549277
92559278 // shortcuts
9256- if (!options.noglobstar && pattern === '**') return GLOBSTAR
9279+ if (pattern === '**') {
9280+ if (!options.noglobstar)
9281+ return GLOBSTAR
9282+ else
9283+ pattern = '*'
9284+ }
92579285 if (pattern === '') return ''
92589286
92599287 var re = ''
@@ -9309,10 +9337,12 @@ function parse (pattern, isSub) {
93099337 }
93109338
93119339 switch (c) {
9312- case '/':
9340+ /* istanbul ignore next */
9341+ case '/': {
93139342 // completely not allowed, even escaped.
93149343 // Should already be path-split by now.
93159344 return false
9345+ }
93169346
93179347 case '\\':
93189348 clearStateChar()
@@ -9431,25 +9461,23 @@ function parse (pattern, isSub) {
94319461
94329462 // handle the case where we left a class open.
94339463 // "[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
94539481 }
94549482
94559483 // finish up the class.
@@ -9533,9 +9561,7 @@ function parse (pattern, isSub) {
95339561 // something that could conceivably capture a dot
95349562 var addPatternStart = false
95359563 switch (re.charAt(0)) {
9536- case '.':
9537- case '[':
9538- case '(': addPatternStart = true
9564+ case '[': case '.': case '(': addPatternStart = true
95399565 }
95409566
95419567 // Hack to work around lack of negative lookbehind in JS
@@ -9597,7 +9623,7 @@ function parse (pattern, isSub) {
95979623 var flags = options.nocase ? 'i' : ''
95989624 try {
95999625 var regExp = new RegExp('^' + re + '$', flags)
9600- } catch (er) {
9626+ } catch (er) /* istanbul ignore next - should be impossible */ {
96019627 // If it was an invalid regular expression, then it can't match
96029628 // anything. This trick looks for a character after the end of
96039629 // the string, which is of course impossible, except in multi-line
@@ -9655,7 +9681,7 @@ function makeRe () {
96559681
96569682 try {
96579683 this.regexp = new RegExp(re, flags)
9658- } catch (ex) {
9684+ } catch (ex) /* istanbul ignore next - should be impossible */ {
96599685 this.regexp = false
96609686 }
96619687 return this.regexp
@@ -9673,8 +9699,8 @@ minimatch.match = function (list, pattern, options) {
96739699 return list
96749700}
96759701
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
96789704 this.debug('match', f, this.pattern)
96799705 // short-circuit in the case of busted things.
96809706 // comments, etc.
@@ -9756,6 +9782,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
97569782
97579783 // should be impossible.
97589784 // some invalid regexp stuff in the set.
9785+ /* istanbul ignore if */
97599786 if (p === false) return false
97609787
97619788 if (p === GLOBSTAR) {
@@ -9829,6 +9856,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
98299856 // no match was found.
98309857 // However, in partial mode, we can't say this is necessarily over.
98319858 // If there's more *pattern* left, then
9859+ /* istanbul ignore if */
98329860 if (partial) {
98339861 // ran out of file
98349862 this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
@@ -9842,11 +9870,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
98429870 // patterns with magic have been turned into regexps.
98439871 var hit
98449872 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
98509874 this.debug('string match', p, f, hit)
98519875 } else {
98529876 hit = f.match(p)
@@ -9877,16 +9901,16 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
98779901 // this is ok if we're doing the match as part of
98789902 // a glob fs traversal.
98799903 return partial
9880- } else if (pi === pl) {
9904+ } else /* istanbul ignore else */ if (pi === pl) {
98819905 // ran out of pattern, still have file left.
98829906 // this is only acceptable if we're on the very last
98839907 // empty segment of a file with a trailing slash.
98849908 // a/* should match a/b/
9885- var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
9886- return emptyFileEnd
9909+ return (fi === fl - 1) && (file[fi] === '')
98879910 }
98889911
98899912 // should be unreachable.
9913+ /* istanbul ignore next */
98909914 throw new Error('wtf?')
98919915}
98929916
0 commit comments