Skip to content

Commit 236e3b4

Browse files
committed
1 parent 1dd2f7e commit 236e3b4

File tree

3 files changed

+105
-78
lines changed

3 files changed

+105
-78
lines changed

node_modules/minimatch/minimatch.js

Lines changed: 93 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module.exports = minimatch
22
minimatch.Minimatch = Minimatch
33

4-
var path = { sep: '/' }
5-
try {
6-
path = require('path')
7-
} catch (er) {}
4+
var path = (function () { try { return require('path') } catch (e) {}}()) || {
5+
sep: '/'
6+
}
7+
minimatch.sep = path.sep
88

99
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
1010
var expand = require('brace-expansion')
@@ -56,43 +56,64 @@ function filter (pattern, options) {
5656
}
5757

5858
function ext (a, b) {
59-
a = a || {}
6059
b = b || {}
6160
var t = {}
62-
Object.keys(b).forEach(function (k) {
63-
t[k] = b[k]
64-
})
6561
Object.keys(a).forEach(function (k) {
6662
t[k] = a[k]
6763
})
64+
Object.keys(b).forEach(function (k) {
65+
t[k] = b[k]
66+
})
6867
return t
6968
}
7069

7170
minimatch.defaults = function (def) {
72-
if (!def || !Object.keys(def).length) return minimatch
71+
if (!def || typeof def !== 'object' || !Object.keys(def).length) {
72+
return minimatch
73+
}
7374

7475
var orig = minimatch
7576

7677
var m = function minimatch (p, pattern, options) {
77-
return orig.minimatch(p, pattern, ext(def, options))
78+
return orig(p, pattern, ext(def, options))
7879
}
7980

8081
m.Minimatch = function Minimatch (pattern, options) {
8182
return new orig.Minimatch(pattern, ext(def, options))
8283
}
84+
m.Minimatch.defaults = function defaults (options) {
85+
return orig.defaults(ext(def, options)).Minimatch
86+
}
87+
88+
m.filter = function filter (pattern, options) {
89+
return orig.filter(pattern, ext(def, options))
90+
}
91+
92+
m.defaults = function defaults (options) {
93+
return orig.defaults(ext(def, options))
94+
}
95+
96+
m.makeRe = function makeRe (pattern, options) {
97+
return orig.makeRe(pattern, ext(def, options))
98+
}
99+
100+
m.braceExpand = function braceExpand (pattern, options) {
101+
return orig.braceExpand(pattern, ext(def, options))
102+
}
103+
104+
m.match = function (list, pattern, options) {
105+
return orig.match(list, pattern, ext(def, options))
106+
}
83107

84108
return m
85109
}
86110

87111
Minimatch.defaults = function (def) {
88-
if (!def || !Object.keys(def).length) return Minimatch
89112
return minimatch.defaults(def).Minimatch
90113
}
91114

92115
function minimatch (p, pattern, options) {
93-
if (typeof pattern !== 'string') {
94-
throw new TypeError('glob pattern string required')
95-
}
116+
assertValidPattern(pattern)
96117

97118
if (!options) options = {}
98119

@@ -101,9 +122,6 @@ function minimatch (p, pattern, options) {
101122
return false
102123
}
103124

104-
// "" only matches ""
105-
if (pattern.trim() === '') return p === ''
106-
107125
return new Minimatch(pattern, options).match(p)
108126
}
109127

@@ -112,15 +130,14 @@ function Minimatch (pattern, options) {
112130
return new Minimatch(pattern, options)
113131
}
114132

115-
if (typeof pattern !== 'string') {
116-
throw new TypeError('glob pattern string required')
117-
}
133+
assertValidPattern(pattern)
118134

119135
if (!options) options = {}
136+
120137
pattern = pattern.trim()
121138

122139
// windows support: need to use /, not \
123-
if (path.sep !== '/') {
140+
if (!options.allowWindowsEscape && path.sep !== '/') {
124141
pattern = pattern.split(path.sep).join('/')
125142
}
126143

@@ -131,6 +148,7 @@ function Minimatch (pattern, options) {
131148
this.negate = false
132149
this.comment = false
133150
this.empty = false
151+
this.partial = !!options.partial
134152

135153
// make the set of regexps etc.
136154
this.make()
@@ -140,9 +158,6 @@ Minimatch.prototype.debug = function () {}
140158

141159
Minimatch.prototype.make = make
142160
function make () {
143-
// don't do it more than once.
144-
if (this._made) return
145-
146161
var pattern = this.pattern
147162
var options = this.options
148163

@@ -162,7 +177,7 @@ function make () {
162177
// step 2: expand braces
163178
var set = this.globSet = this.braceExpand()
164179

165-
if (options.debug) this.debug = console.error
180+
if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }
166181

167182
this.debug(this.pattern, set)
168183

@@ -242,19 +257,29 @@ function braceExpand (pattern, options) {
242257
pattern = typeof pattern === 'undefined'
243258
? this.pattern : pattern
244259

245-
if (typeof pattern === 'undefined') {
246-
throw new TypeError('undefined pattern')
247-
}
260+
assertValidPattern(pattern)
248261

249-
if (options.nobrace ||
250-
!pattern.match(/\{.*\}/)) {
262+
// Thanks to Yeting Li <https://github.com/yetingli> for
263+
// improving this regexp to avoid a ReDOS vulnerability.
264+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
251265
// shortcut. no need to expand.
252266
return [pattern]
253267
}
254268

255269
return expand(pattern)
256270
}
257271

272+
var MAX_PATTERN_LENGTH = 1024 * 64
273+
var assertValidPattern = function (pattern) {
274+
if (typeof pattern !== 'string') {
275+
throw new TypeError('invalid pattern')
276+
}
277+
278+
if (pattern.length > MAX_PATTERN_LENGTH) {
279+
throw new TypeError('pattern is too long')
280+
}
281+
}
282+
258283
// parse a component of the expanded set.
259284
// At this point, no pattern may contain "/" in it
260285
// so we're going to return a 2d array, where each entry is the full
@@ -269,14 +294,17 @@ function braceExpand (pattern, options) {
269294
Minimatch.prototype.parse = parse
270295
var SUBPARSE = {}
271296
function parse (pattern, isSub) {
272-
if (pattern.length > 1024 * 64) {
273-
throw new TypeError('pattern is too long')
274-
}
297+
assertValidPattern(pattern)
275298

276299
var options = this.options
277300

278301
// shortcuts
279-
if (!options.noglobstar && pattern === '**') return GLOBSTAR
302+
if (pattern === '**') {
303+
if (!options.noglobstar)
304+
return GLOBSTAR
305+
else
306+
pattern = '*'
307+
}
280308
if (pattern === '') return ''
281309

282310
var re = ''
@@ -332,10 +360,12 @@ function parse (pattern, isSub) {
332360
}
333361

334362
switch (c) {
335-
case '/':
363+
/* istanbul ignore next */
364+
case '/': {
336365
// completely not allowed, even escaped.
337366
// Should already be path-split by now.
338367
return false
368+
}
339369

340370
case '\\':
341371
clearStateChar()
@@ -454,25 +484,23 @@ function parse (pattern, isSub) {
454484

455485
// handle the case where we left a class open.
456486
// "[z-a]" is valid, equivalent to "\[z-a\]"
457-
if (inClass) {
458-
// split where the last [ was, make sure we don't have
459-
// an invalid re. if so, re-walk the contents of the
460-
// would-be class to re-translate any characters that
461-
// were passed through as-is
462-
// TODO: It would probably be faster to determine this
463-
// without a try/catch and a new RegExp, but it's tricky
464-
// to do safely. For now, this is safe and works.
465-
var cs = pattern.substring(classStart + 1, i)
466-
try {
467-
RegExp('[' + cs + ']')
468-
} catch (er) {
469-
// not a valid class!
470-
var sp = this.parse(cs, SUBPARSE)
471-
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
472-
hasMagic = hasMagic || sp[1]
473-
inClass = false
474-
continue
475-
}
487+
// split where the last [ was, make sure we don't have
488+
// an invalid re. if so, re-walk the contents of the
489+
// would-be class to re-translate any characters that
490+
// were passed through as-is
491+
// TODO: It would probably be faster to determine this
492+
// without a try/catch and a new RegExp, but it's tricky
493+
// to do safely. For now, this is safe and works.
494+
var cs = pattern.substring(classStart + 1, i)
495+
try {
496+
RegExp('[' + cs + ']')
497+
} catch (er) {
498+
// not a valid class!
499+
var sp = this.parse(cs, SUBPARSE)
500+
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
501+
hasMagic = hasMagic || sp[1]
502+
inClass = false
503+
continue
476504
}
477505

478506
// finish up the class.
@@ -556,9 +584,7 @@ function parse (pattern, isSub) {
556584
// something that could conceivably capture a dot
557585
var addPatternStart = false
558586
switch (re.charAt(0)) {
559-
case '.':
560-
case '[':
561-
case '(': addPatternStart = true
587+
case '[': case '.': case '(': addPatternStart = true
562588
}
563589

564590
// Hack to work around lack of negative lookbehind in JS
@@ -620,7 +646,7 @@ function parse (pattern, isSub) {
620646
var flags = options.nocase ? 'i' : ''
621647
try {
622648
var regExp = new RegExp('^' + re + '$', flags)
623-
} catch (er) {
649+
} catch (er) /* istanbul ignore next - should be impossible */ {
624650
// If it was an invalid regular expression, then it can't match
625651
// anything. This trick looks for a character after the end of
626652
// the string, which is of course impossible, except in multi-line
@@ -678,7 +704,7 @@ function makeRe () {
678704

679705
try {
680706
this.regexp = new RegExp(re, flags)
681-
} catch (ex) {
707+
} catch (ex) /* istanbul ignore next - should be impossible */ {
682708
this.regexp = false
683709
}
684710
return this.regexp
@@ -696,8 +722,8 @@ minimatch.match = function (list, pattern, options) {
696722
return list
697723
}
698724

699-
Minimatch.prototype.match = match
700-
function match (f, partial) {
725+
Minimatch.prototype.match = function match (f, partial) {
726+
if (typeof partial === 'undefined') partial = this.partial
701727
this.debug('match', f, this.pattern)
702728
// short-circuit in the case of busted things.
703729
// comments, etc.
@@ -779,6 +805,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
779805

780806
// should be impossible.
781807
// some invalid regexp stuff in the set.
808+
/* istanbul ignore if */
782809
if (p === false) return false
783810

784811
if (p === GLOBSTAR) {
@@ -852,6 +879,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
852879
// no match was found.
853880
// However, in partial mode, we can't say this is necessarily over.
854881
// If there's more *pattern* left, then
882+
/* istanbul ignore if */
855883
if (partial) {
856884
// ran out of file
857885
this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
@@ -865,11 +893,7 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
865893
// patterns with magic have been turned into regexps.
866894
var hit
867895
if (typeof p === 'string') {
868-
if (options.nocase) {
869-
hit = f.toLowerCase() === p.toLowerCase()
870-
} else {
871-
hit = f === p
872-
}
896+
hit = f === p
873897
this.debug('string match', p, f, hit)
874898
} else {
875899
hit = f.match(p)
@@ -900,16 +924,16 @@ Minimatch.prototype.matchOne = function (file, pattern, partial) {
900924
// this is ok if we're doing the match as part of
901925
// a glob fs traversal.
902926
return partial
903-
} else if (pi === pl) {
927+
} else /* istanbul ignore else */ if (pi === pl) {
904928
// ran out of pattern, still have file left.
905929
// this is only acceptable if we're on the very last
906930
// empty segment of a file with a trailing slash.
907931
// a/* should match a/b/
908-
var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
909-
return emptyFileEnd
932+
return (fi === fl - 1) && (file[fi] === '')
910933
}
911934

912935
// should be unreachable.
936+
/* istanbul ignore next */
913937
throw new Error('wtf?')
914938
}
915939

node_modules/minimatch/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me)",
33
"name": "minimatch",
44
"description": "a glob matcher in javascript",
5-
"version": "3.0.4",
5+
"version": "3.1.2",
6+
"publishConfig": {
7+
"tag": "v3-legacy"
8+
},
69
"repository": {
710
"type": "git",
811
"url": "git://github.com/isaacs/minimatch.git"
912
},
1013
"main": "minimatch.js",
1114
"scripts": {
12-
"test": "tap test/*.js --cov",
15+
"test": "tap",
1316
"preversion": "npm test",
1417
"postversion": "npm publish",
1518
"postpublish": "git push origin --all; git push origin --tags"
@@ -21,7 +24,7 @@
2124
"brace-expansion": "^1.1.7"
2225
},
2326
"devDependencies": {
24-
"tap": "^10.3.2"
27+
"tap": "^15.1.6"
2528
},
2629
"license": "ISC",
2730
"files": [

0 commit comments

Comments
 (0)