minimatch 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +15 -0
  2. package/minimatch.js +50 -53
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -171,6 +171,21 @@ Suppress the behavior of treating a leading `!` character as negation.
171
171
  Returns from negate expressions the same as if they were not negated.
172
172
  (Ie, true on a hit, false on a miss.)
173
173
 
174
+ ### partial
175
+
176
+ Compare a partial path to a pattern. As long as the parts of the path that
177
+ are present are not contradicted by the pattern, it will be treated as a
178
+ match. This is useful in applications where you're walking through a
179
+ folder structure, and don't yet have the full path, but want to ensure that
180
+ you do not walk down paths that can never be a match.
181
+
182
+ For example,
183
+
184
+ ```js
185
+ minimatch('/a/b', '/a/*/c/d', { partial: true }) // true, might be /a/b/c/d
186
+ minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d
187
+ minimatch('/x/y/z', '/a/**/z', { partial: true }) // false, because x !== a
188
+ ```
174
189
 
175
190
  ## Comparisons to other fnmatch/glob implementations
176
191
 
package/minimatch.js CHANGED
@@ -1,15 +1,15 @@
1
1
  module.exports = minimatch
2
2
  minimatch.Minimatch = Minimatch
3
3
 
4
- const path = (() => { try { return require('path') } catch (e) {}})() || {
4
+ var path = (function () { try { return require('path') } catch (e) {}}()) || {
5
5
  sep: '/'
6
6
  }
7
7
  minimatch.sep = path.sep
8
8
 
9
- const GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
10
- const expand = require('brace-expansion')
9
+ var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
10
+ var expand = require('brace-expansion')
11
11
 
12
- const plTypes = {
12
+ var plTypes = {
13
13
  '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
14
14
  '?': { open: '(?:', close: ')?' },
15
15
  '+': { open: '(?:', close: ')+' },
@@ -19,22 +19,22 @@ const plTypes = {
19
19
 
20
20
  // any single thing other than /
21
21
  // don't need to escape / when using new RegExp()
22
- const qmark = '[^/]'
22
+ var qmark = '[^/]'
23
23
 
24
24
  // * => any number of characters
25
- const star = qmark + '*?'
25
+ var star = qmark + '*?'
26
26
 
27
27
  // ** when dots are allowed. Anything goes, except .. and .
28
28
  // not (^ or / followed by one or two dots followed by $ or /),
29
29
  // followed by anything, any number of times.
30
- const twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
30
+ var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
31
31
 
32
32
  // not a ^ or / followed by a dot,
33
33
  // followed by anything, any number of times.
34
- const twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
34
+ var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
35
35
 
36
36
  // characters that need to be escaped in RegExp.
37
- const reSpecials = charSet('().*{}+?[]^$\\!')
37
+ var reSpecials = charSet('().*{}+?[]^$\\!')
38
38
 
39
39
  // "abc" -> { a:true, b:true, c:true }
40
40
  function charSet (s) {
@@ -45,7 +45,7 @@ function charSet (s) {
45
45
  }
46
46
 
47
47
  // normalizes slashes.
48
- const slashSplit = /\/+/
48
+ var slashSplit = /\/+/
49
49
 
50
50
  minimatch.filter = filter
51
51
  function filter (pattern, options) {
@@ -56,9 +56,8 @@ function filter (pattern, options) {
56
56
  }
57
57
 
58
58
  function ext (a, b) {
59
- a = a || {}
60
59
  b = b || {}
61
- const t = {}
60
+ var t = {}
62
61
  Object.keys(a).forEach(function (k) {
63
62
  t[k] = a[k]
64
63
  })
@@ -73,16 +72,16 @@ minimatch.defaults = function (def) {
73
72
  return minimatch
74
73
  }
75
74
 
76
- const orig = minimatch
75
+ var orig = minimatch
77
76
 
78
- const m = function minimatch (p, pattern, options) {
77
+ var m = function minimatch (p, pattern, options) {
79
78
  return orig(p, pattern, ext(def, options))
80
79
  }
81
80
 
82
81
  m.Minimatch = function Minimatch (pattern, options) {
83
82
  return new orig.Minimatch(pattern, ext(def, options))
84
83
  }
85
- m.Minimatch.defaults = options => {
84
+ m.Minimatch.defaults = function defaults (options) {
86
85
  return orig.defaults(ext(def, options)).Minimatch
87
86
  }
88
87
 
@@ -123,9 +122,6 @@ function minimatch (p, pattern, options) {
123
122
  return false
124
123
  }
125
124
 
126
- // "" only matches ""
127
- if (pattern.trim() === '') return p === ''
128
-
129
125
  return new Minimatch(pattern, options).match(p)
130
126
  }
131
127
 
@@ -137,7 +133,6 @@ function Minimatch (pattern, options) {
137
133
  assertValidPattern(pattern)
138
134
 
139
135
  if (!options) options = {}
140
- pattern = pattern.trim()
141
136
 
142
137
  // windows support: need to use /, not \
143
138
  if (path.sep !== '/') {
@@ -151,6 +146,7 @@ function Minimatch (pattern, options) {
151
146
  this.negate = false
152
147
  this.comment = false
153
148
  this.empty = false
149
+ this.partial = !!options.partial
154
150
 
155
151
  // make the set of regexps etc.
156
152
  this.make()
@@ -160,9 +156,6 @@ Minimatch.prototype.debug = function () {}
160
156
 
161
157
  Minimatch.prototype.make = make
162
158
  function make () {
163
- // don't do it more than once.
164
- if (this._made) return
165
-
166
159
  var pattern = this.pattern
167
160
  var options = this.options
168
161
 
@@ -182,7 +175,7 @@ function make () {
182
175
  // step 2: expand braces
183
176
  var set = this.globSet = this.braceExpand()
184
177
 
185
- if (options.debug) this.debug = console.error
178
+ if (options.debug) this.debug = function debug() { console.error.apply(console, arguments) }
186
179
 
187
180
  this.debug(this.pattern, set)
188
181
 
@@ -264,6 +257,8 @@ function braceExpand (pattern, options) {
264
257
 
265
258
  assertValidPattern(pattern)
266
259
 
260
+ // Thanks to Yeting Li <https://github.com/yetingli> for
261
+ // improving this regexp to avoid a ReDOS vulnerability.
267
262
  if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
268
263
  // shortcut. no need to expand.
269
264
  return [pattern]
@@ -272,8 +267,8 @@ function braceExpand (pattern, options) {
272
267
  return expand(pattern)
273
268
  }
274
269
 
275
- const MAX_PATTERN_LENGTH = 1024 * 64
276
- const assertValidPattern = pattern => {
270
+ var MAX_PATTERN_LENGTH = 1024 * 64
271
+ var assertValidPattern = function (pattern) {
277
272
  if (typeof pattern !== 'string') {
278
273
  throw new TypeError('invalid pattern')
279
274
  }
@@ -295,14 +290,19 @@ const assertValidPattern = pattern => {
295
290
  // of * is equivalent to a single *. Globstar behavior is enabled by
296
291
  // default, and can be disabled by setting options.noglobstar.
297
292
  Minimatch.prototype.parse = parse
298
- const SUBPARSE = {}
293
+ var SUBPARSE = {}
299
294
  function parse (pattern, isSub) {
300
295
  assertValidPattern(pattern)
301
296
 
302
297
  var options = this.options
303
298
 
304
299
  // shortcuts
305
- if (!options.noglobstar && pattern === '**') return GLOBSTAR
300
+ if (pattern === '**') {
301
+ if (!options.noglobstar)
302
+ return GLOBSTAR
303
+ else
304
+ pattern = '*'
305
+ }
306
306
  if (pattern === '') return ''
307
307
 
308
308
  var re = ''
@@ -358,7 +358,8 @@ function parse (pattern, isSub) {
358
358
  }
359
359
 
360
360
  switch (c) {
361
- case '/': /* istanbul ignore next */ {
361
+ /* istanbul ignore next */
362
+ case '/': {
362
363
  // completely not allowed, even escaped.
363
364
  // Should already be path-split by now.
364
365
  return false
@@ -481,25 +482,23 @@ function parse (pattern, isSub) {
481
482
 
482
483
  // handle the case where we left a class open.
483
484
  // "[z-a]" is valid, equivalent to "\[z-a\]"
484
- if (inClass) {
485
- // split where the last [ was, make sure we don't have
486
- // an invalid re. if so, re-walk the contents of the
487
- // would-be class to re-translate any characters that
488
- // were passed through as-is
489
- // TODO: It would probably be faster to determine this
490
- // without a try/catch and a new RegExp, but it's tricky
491
- // to do safely. For now, this is safe and works.
492
- var cs = pattern.substring(classStart + 1, i)
493
- try {
494
- RegExp('[' + cs + ']')
495
- } catch (er) {
496
- // not a valid class!
497
- var sp = this.parse(cs, SUBPARSE)
498
- re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
499
- hasMagic = hasMagic || sp[1]
500
- inClass = false
501
- continue
502
- }
485
+ // split where the last [ was, make sure we don't have
486
+ // an invalid re. if so, re-walk the contents of the
487
+ // would-be class to re-translate any characters that
488
+ // were passed through as-is
489
+ // TODO: It would probably be faster to determine this
490
+ // without a try/catch and a new RegExp, but it's tricky
491
+ // to do safely. For now, this is safe and works.
492
+ var cs = pattern.substring(classStart + 1, i)
493
+ try {
494
+ RegExp('[' + cs + ']')
495
+ } catch (er) {
496
+ // not a valid class!
497
+ var sp = this.parse(cs, SUBPARSE)
498
+ re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
499
+ hasMagic = hasMagic || sp[1]
500
+ inClass = false
501
+ continue
503
502
  }
504
503
 
505
504
  // finish up the class.
@@ -583,9 +582,7 @@ function parse (pattern, isSub) {
583
582
  // something that could conceivably capture a dot
584
583
  var addPatternStart = false
585
584
  switch (re.charAt(0)) {
586
- case '.':
587
- case '[':
588
- case '(': addPatternStart = true
585
+ case '[': case '.': case '(': addPatternStart = true
589
586
  }
590
587
 
591
588
  // Hack to work around lack of negative lookbehind in JS
@@ -713,7 +710,7 @@ function makeRe () {
713
710
 
714
711
  minimatch.match = function (list, pattern, options) {
715
712
  options = options || {}
716
- const mm = new Minimatch(pattern, options)
713
+ var mm = new Minimatch(pattern, options)
717
714
  list = list.filter(function (f) {
718
715
  return mm.match(f)
719
716
  })
@@ -723,8 +720,8 @@ minimatch.match = function (list, pattern, options) {
723
720
  return list
724
721
  }
725
722
 
726
- Minimatch.prototype.match = match
727
- function match (f, partial) {
723
+ Minimatch.prototype.match = function match (f, partial) {
724
+ if (typeof partial === 'undefined') partial = this.partial
728
725
  this.debug('match', f, this.pattern)
729
726
  // short-circuit in the case of busted things.
730
727
  // comments, etc.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
3
3
  "name": "minimatch",
4
4
  "description": "a glob matcher in javascript",
5
- "version": "3.0.5",
5
+ "version": "3.0.6",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/isaacs/minimatch.git"