Skip to content

Commit 76bbdfa

Browse files
Update minimatch (#558)
1 parent 1aafadc commit 76bbdfa

File tree

4 files changed

+193
-145
lines changed

4 files changed

+193
-145
lines changed

.licenses/npm/minimatch.dep.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cache-save/index.js

+93-69
Original file line numberDiff line numberDiff line change
@@ -45304,10 +45304,10 @@ function populateMaps (extensions, types) {
4530445304
module.exports = minimatch
4530545305
minimatch.Minimatch = Minimatch
4530645306

45307-
var path = { sep: '/' }
45308-
try {
45309-
path = __nccwpck_require__(1017)
45310-
} catch (er) {}
45307+
var path = (function () { try { return __nccwpck_require__(1017) } catch (e) {}}()) || {
45308+
sep: '/'
45309+
}
45310+
minimatch.sep = path.sep
4531145311

4531245312
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
4531345313
var expand = __nccwpck_require__(3717)
@@ -45359,43 +45359,64 @@ function filter (pattern, options) {
4535945359
}
4536045360

4536145361
function ext (a, b) {
45362-
a = a || {}
4536345362
b = b || {}
4536445363
var t = {}
45365-
Object.keys(b).forEach(function (k) {
45366-
t[k] = b[k]
45367-
})
4536845364
Object.keys(a).forEach(function (k) {
4536945365
t[k] = a[k]
4537045366
})
45367+
Object.keys(b).forEach(function (k) {
45368+
t[k] = b[k]
45369+
})
4537145370
return t
4537245371
}
4537345372

4537445373
minimatch.defaults = function (def) {
45375-
if (!def || !Object.keys(def).length) return minimatch
45374+
if (!def || typeof def !== 'object' || !Object.keys(def).length) {
45375+
return minimatch
45376+
}
4537645377

4537745378
var orig = minimatch
4537845379

4537945380
var m = function minimatch (p, pattern, options) {
45380-
return orig.minimatch(p, pattern, ext(def, options))
45381+
return orig(p, pattern, ext(def, options))
4538145382
}
4538245383

4538345384
m.Minimatch = function Minimatch (pattern, options) {
4538445385
return new orig.Minimatch(pattern, ext(def, options))
4538545386
}
45387+
m.Minimatch.defaults = function defaults (options) {
45388+
return orig.defaults(ext(def, options)).Minimatch
45389+
}
45390+
45391+
m.filter = function filter (pattern, options) {
45392+
return orig.filter(pattern, ext(def, options))
45393+
}
45394+
45395+
m.defaults = function defaults (options) {
45396+
return orig.defaults(ext(def, options))
45397+
}
45398+
45399+
m.makeRe = function makeRe (pattern, options) {
45400+
return orig.makeRe(pattern, ext(def, options))
45401+
}
45402+
45403+
m.braceExpand = function braceExpand (pattern, options) {
45404+
return orig.braceExpand(pattern, ext(def, options))
45405+
}
45406+
45407+
m.match = function (list, pattern, options) {
45408+
return orig.match(list, pattern, ext(def, options))
45409+
}
4538645410

4538745411
return m
4538845412
}
4538945413

4539045414
Minimatch.defaults = function (def) {
45391-
if (!def || !Object.keys(def).length) return Minimatch
4539245415
return minimatch.defaults(def).Minimatch
4539345416
}
4539445417

4539545418
function minimatch (p, pattern, options) {
45396-
if (typeof pattern !== 'string') {
45397-
throw new TypeError('glob pattern string required')
45398-
}
45419+
assertValidPattern(pattern)
4539945420

4540045421
if (!options) options = {}
4540145422

@@ -45404,9 +45425,6 @@ function minimatch (p, pattern, options) {
4540445425
return false
4540545426
}
4540645427

45407-
// "" only matches ""
45408-
if (pattern.trim() === '') return p === ''
45409-
4541045428
return new Minimatch(pattern, options).match(p)
4541145429
}
4541245430

@@ -45415,15 +45433,14 @@ function Minimatch (pattern, options) {
4541545433
return new Minimatch(pattern, options)
4541645434
}
4541745435

45418-
if (typeof pattern !== 'string') {
45419-
throw new TypeError('glob pattern string required')
45420-
}
45436+
assertValidPattern(pattern)
4542145437

4542245438
if (!options) options = {}
45439+
4542345440
pattern = pattern.trim()
4542445441

4542545442
// windows support: need to use /, not \
45426-
if (path.sep !== '/') {
45443+
if (!options.allowWindowsEscape && path.sep !== '/') {
4542745444
pattern = pattern.split(path.sep).join('/')
4542845445
}
4542945446

@@ -45434,6 +45451,7 @@ function Minimatch (pattern, options) {
4543445451
this.negate = false
4543545452
this.comment = false
4543645453
this.empty = false
45454+
this.partial = !!options.partial
4543745455

4543845456
// make the set of regexps etc.
4543945457
this.make()
@@ -45443,9 +45461,6 @@ Minimatch.prototype.debug = function () {}
4544345461

4544445462
Minimatch.prototype.make = make
4544545463
function make () {
45446-
// don't do it more than once.
45447-
if (this._made) return
45448-
4544945464
var pattern = this.pattern
4545045465
var options = this.options
4545145466

@@ -45465,7 +45480,7 @@ function make () {
4546545480
// step 2: expand braces
4546645481
var set = this.globSet = this.braceExpand()
4546745482

45468-
if (options.debug) this.debug = console.error
45483+
if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }
4546945484

4547045485
this.debug(this.pattern, set)
4547145486

@@ -45545,19 +45560,29 @@ function braceExpand (pattern, options) {
4554545560
pattern = typeof pattern === 'undefined'
4554645561
? this.pattern : pattern
4554745562

45548-
if (typeof pattern === 'undefined') {
45549-
throw new TypeError('undefined pattern')
45550-
}
45563+
assertValidPattern(pattern)
4555145564

45552-
if (options.nobrace ||
45553-
!pattern.match(/\{.*\}/)) {
45565+
// Thanks to Yeting Li <https://github.com/yetingli> for
45566+
// improving this regexp to avoid a ReDOS vulnerability.
45567+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
4555445568
// shortcut. no need to expand.
4555545569
return [pattern]
4555645570
}
4555745571

4555845572
return expand(pattern)
4555945573
}
4556045574

45575+
var MAX_PATTERN_LENGTH = 1024 * 64
45576+
var assertValidPattern = function (pattern) {
45577+
if (typeof pattern !== 'string') {
45578+
throw new TypeError('invalid pattern')
45579+
}
45580+
45581+
if (pattern.length > MAX_PATTERN_LENGTH) {
45582+
throw new TypeError('pattern is too long')
45583+
}
45584+
}
45585+
4556145586
// parse a component of the expanded set.
4556245587
// At this point, no pattern may contain "/" in it
4556345588
// so we're going to return a 2d array, where each entry is the full
@@ -45572,14 +45597,17 @@ function braceExpand (pattern, options) {
4557245597
Minimatch.prototype.parse = parse
4557345598
var SUBPARSE = {}
4557445599
function parse (pattern, isSub) {
45575-
if (pattern.length > 1024 * 64) {
45576-
throw new TypeError('pattern is too long')
45577-
}
45600+
assertValidPattern(pattern)
4557845601

4557945602
var options = this.options
4558045603

4558145604
// shortcuts
45582-
if (!options.noglobstar && pattern === '**') return GLOBSTAR
45605+
if (pattern === '**') {
45606+
if (!options.noglobstar)
45607+
return GLOBSTAR
45608+
else
45609+
pattern = '*'
45610+
}
4558345611
if (pattern === '') return ''
4558445612

4558545613
var re = ''
@@ -45635,10 +45663,12 @@ function parse (pattern, isSub) {
4563545663
}
4563645664

4563745665
switch (c) {
45638-
case '/':
45666+
/* istanbul ignore next */
45667+
case '/': {
4563945668
// completely not allowed, even escaped.
4564045669
// Should already be path-split by now.
4564145670
return false
45671+
}
4564245672

4564345673
case '\\':
4564445674
clearStateChar()
@@ -45757,25 +45787,23 @@ function parse (pattern, isSub) {
4575745787

4575845788
// handle the case where we left a class open.
4575945789
// "[z-a]" is valid, equivalent to "\[z-a\]"
45760-
if (inClass) {
45761-
// split where the last [ was, make sure we don't have
45762-
// an invalid re. if so, re-walk the contents of the
45763-
// would-be class to re-translate any characters that
45764-
// were passed through as-is
45765-
// TODO: It would probably be faster to determine this
45766-
// without a try/catch and a new RegExp, but it's tricky
45767-
// to do safely. For now, this is safe and works.
45768-
var cs = pattern.substring(classStart + 1, i)
45769-
try {
45770-
RegExp('[' + cs + ']')
45771-
} catch (er) {
45772-
// not a valid class!
45773-
var sp = this.parse(cs, SUBPARSE)
45774-
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
45775-
hasMagic = hasMagic || sp[1]
45776-
inClass = false
45777-
continue
45778-
}
45790+
// split where the last [ was, make sure we don't have
45791+
// an invalid re. if so, re-walk the contents of the
45792+
// would-be class to re-translate any characters that
45793+
// were passed through as-is
45794+
// TODO: It would probably be faster to determine this
45795+
// without a try/catch and a new RegExp, but it's tricky
45796+
// to do safely. For now, this is safe and works.
45797+
var cs = pattern.substring(classStart + 1, i)
45798+
try {
45799+
RegExp('[' + cs + ']')
45800+
} catch (er) {
45801+
// not a valid class!
45802+
var sp = this.parse(cs, SUBPARSE)
45803+
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
45804+
hasMagic = hasMagic || sp[1]
45805+
inClass = false
45806+
continue
4577945807
}
4578045808

4578145809
// finish up the class.
@@ -45859,9 +45887,7 @@ function parse (pattern, isSub) {
4585945887
// something that could conceivably capture a dot
4586045888
var addPatternStart = false
4586145889
switch (re.charAt(0)) {
45862-
case '.':
45863-
case '[':
45864-
case '(': addPatternStart = true
45890+
case '[': case '.': case '(': addPatternStart = true
4586545891
}
4586645892

4586745893
// Hack to work around lack of negative lookbehind in JS
@@ -45923,7 +45949,7 @@ function parse (pattern, isSub) {
4592345949
var flags = options.nocase ? 'i' : ''
4592445950
try {
4592545951
var regExp = new RegExp('^' + re + '$', flags)
45926-
} catch (er) {
45952+
} catch (er) /* istanbul ignore next - should be impossible */ {
4592745953
// If it was an invalid regular expression, then it can't match
4592845954
// anything. This trick looks for a character after the end of
4592945955
// the string, which is of course impossible, except in multi-line
@@ -45981,7 +46007,7 @@ function makeRe () {
4598146007

4598246008
try {
4598346009
this.regexp = new RegExp(re, flags)
45984-
} catch (ex) {
46010+
} catch (ex) /* istanbul ignore next - should be impossible */ {
4598546011
this.regexp = false
4598646012
}
4598746013
return this.regexp
@@ -45999,8 +46025,8 @@ minimatch.match = function (list, pattern, options) {
4599946025
return list
4600046026
}
4600146027

46002-
Minimatch.prototype.match = match
46003-
function match (f, partial) {
46028+
Minimatch.prototype.match = function match (f, partial) {
46029+
if (typeof partial === 'undefined') partial = this.partial
4600446030
this.debug('match', f, this.pattern)
4600546031
// short-circuit in the case of busted things.
4600646032
// comments, etc.
@@ -46082,6 +46108,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
4608246108

4608346109
// should be impossible.
4608446110
// some invalid regexp stuff in the set.
46111+
/* istanbul ignore if */
4608546112
if (p === false) return false
4608646113

4608746114
if (p === GLOBSTAR) {
@@ -46155,6 +46182,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
4615546182
// no match was found.
4615646183
// However, in partial mode, we can't say this is necessarily over.
4615746184
// If there's more *pattern* left, then
46185+
/* istanbul ignore if */
4615846186
if (partial) {
4615946187
// ran out of file
4616046188
this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
@@ -46168,11 +46196,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
4616846196
// patterns with magic have been turned into regexps.
4616946197
var hit
4617046198
if (typeof p === 'string') {
46171-
if (options.nocase) {
46172-
hit = f.toLowerCase() === p.toLowerCase()
46173-
} else {
46174-
hit = f === p
46175-
}
46199+
hit = f === p
4617646200
this.debug('string match', p, f, hit)
4617746201
} else {
4617846202
hit = f.match(p)
@@ -46203,16 +46227,16 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
4620346227
// this is ok if we're doing the match as part of
4620446228
// a glob fs traversal.
4620546229
return partial
46206-
} else if (pi === pl) {
46230+
} else /* istanbul ignore else */ if (pi === pl) {
4620746231
// ran out of pattern, still have file left.
4620846232
// this is only acceptable if we're on the very last
4620946233
// empty segment of a file with a trailing slash.
4621046234
// a/* should match a/b/
46211-
var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
46212-
return emptyFileEnd
46235+
return (fi === fl - 1) && (file[fi] === '')
4621346236
}
4621446237

4621546238
// should be unreachable.
46239+
/* istanbul ignore next */
4621646240
throw new Error('wtf?')
4621746241
}
4621846242

0 commit comments

Comments
 (0)