minimatch 4.0.0 → 4.2.1

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The ISC License
2
2
 
3
- Copyright (c) Isaac Z. Schlueter and Contributors
3
+ Copyright (c) 2011-2022 Isaac Z. Schlueter and Contributors
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -187,6 +187,12 @@ minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d
187
187
  minimatch('/x/y/z', '/a/**/z', { partial: true }) // false, because x !== a
188
188
  ```
189
189
 
190
+ ### allowWindowsEscape
191
+
192
+ Windows path separator `\` is by default converted to `/`, which
193
+ prohibits the usage of `\` as a escape character. This flag skips that
194
+ behavior and allows using the escape character.
195
+
190
196
  ## Comparisons to other fnmatch/glob implementations
191
197
 
192
198
  While strict compliance with the existing standards is a worthwhile
package/minimatch.js CHANGED
@@ -17,6 +17,7 @@ const path = (() => { try { return require('path') } catch (e) {}})() || {
17
17
  minimatch.sep = path.sep
18
18
 
19
19
  const GLOBSTAR = Symbol('globstar **')
20
+ minimatch.GLOBSTAR = GLOBSTAR
20
21
  const expand = require('brace-expansion')
21
22
 
22
23
  const plTypes = {
@@ -167,7 +168,7 @@ class Minimatch {
167
168
  if (!options) options = {}
168
169
 
169
170
  // windows support: need to use /, not \
170
- if (path.sep !== '/') {
171
+ if (!options.allowWindowsEscape && path.sep !== '/') {
171
172
  pattern = pattern.split(path.sep).join('/')
172
173
  }
173
174
 
@@ -363,11 +364,7 @@ class Minimatch {
363
364
  // patterns with magic have been turned into regexps.
364
365
  var hit
365
366
  if (typeof p === 'string') {
366
- if (options.nocase) {
367
- hit = f.toLowerCase() === p.toLowerCase()
368
- } else {
369
- hit = f === p
370
- }
367
+ hit = f === p
371
368
  this.debug('string match', p, f, hit)
372
369
  } else {
373
370
  hit = f.match(p)
@@ -430,7 +427,7 @@ class Minimatch {
430
427
  if (pattern === '') return ''
431
428
 
432
429
  let re = ''
433
- let hasMagic = false
430
+ let hasMagic = !!options.nocase
434
431
  let escaping = false
435
432
  // ? => one single character
436
433
  const patternListStack = []
@@ -475,8 +472,16 @@ class Minimatch {
475
472
  this.debug('%s\t%s %s %j', pattern, i, re, c)
476
473
 
477
474
  // skip over any that are escaped.
478
- if (escaping && reSpecials[c]) {
479
- re += '\\' + c
475
+ if (escaping) {
476
+ /* istanbul ignore next - completely not allowed, even escaped. */
477
+ if (c === '/') {
478
+ return false
479
+ }
480
+
481
+ if (reSpecials[c]) {
482
+ re += '\\'
483
+ }
484
+ re += c
480
485
  escaping = false
481
486
  continue
482
487
  }
@@ -484,7 +489,6 @@ class Minimatch {
484
489
  switch (c) {
485
490
  /* istanbul ignore next */
486
491
  case '/': {
487
- // completely not allowed, even escaped.
488
492
  // Should already be path-split by now.
489
493
  return false
490
494
  }
@@ -567,9 +571,8 @@ class Minimatch {
567
571
  continue
568
572
 
569
573
  case '|':
570
- if (inClass || !patternListStack.length || escaping) {
574
+ if (inClass || !patternListStack.length) {
571
575
  re += '\\|'
572
- escaping = false
573
576
  continue
574
577
  }
575
578
 
@@ -600,7 +603,6 @@ class Minimatch {
600
603
  // first in the list. -- POSIX.2 2.8.3.2
601
604
  if (i === classStart + 1 || !inClass) {
602
605
  re += '\\' + c
603
- escaping = false
604
606
  continue
605
607
  }
606
608
 
@@ -635,15 +637,12 @@ class Minimatch {
635
637
  // swallow any state char that wasn't consumed
636
638
  clearStateChar()
637
639
 
638
- if (escaping) {
639
- // no need
640
- escaping = false
641
- } else if (reSpecials[c]
642
- && !(c === '^' && inClass)) {
640
+ if (reSpecials[c] && !(c === '^' && inClass)) {
643
641
  re += '\\'
644
642
  }
645
643
 
646
644
  re += c
645
+ break
647
646
 
648
647
  } // switch
649
648
  } // for
@@ -673,6 +672,7 @@ class Minimatch {
673
672
  this.debug('setting tail', re, pl)
674
673
  // maybe some even number of \, then maybe 1 \, followed by a |
675
674
  tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
675
+ /* istanbul ignore else - should already be done */
676
676
  if (!$2) {
677
677
  // the | isn't already escaped, so escape it.
678
678
  $2 = '\\'
@@ -794,13 +794,42 @@ class Minimatch {
794
794
  : twoStarNoDot
795
795
  const flags = options.nocase ? 'i' : ''
796
796
 
797
- let re = set.map(pattern =>
798
- pattern.map(p =>
799
- (p === GLOBSTAR) ? twoStar
800
- : (typeof p === 'string') ? regExpEscape(p)
797
+ // coalesce globstars and regexpify non-globstar patterns
798
+ // if it's the only item, then we just do one twoStar
799
+ // if it's the first, and there are more, prepend (\/|twoStar\/)? to next
800
+ // if it's the last, append (\/twoStar|) to previous
801
+ // if it's in the middle, append (\/|\/twoStar\/) to previous
802
+ // then filter out GLOBSTAR symbols
803
+ let re = set.map(pattern => {
804
+ pattern = pattern.map(p =>
805
+ typeof p === 'string' ? regExpEscape(p)
806
+ : p === GLOBSTAR ? GLOBSTAR
801
807
  : p._src
802
- ).join('\\\/')
803
- ).join('|')
808
+ ).reduce((set, p) => {
809
+ if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) {
810
+ set.push(p)
811
+ }
812
+ return set
813
+ }, [])
814
+ pattern.forEach((p, i) => {
815
+ if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) {
816
+ return
817
+ }
818
+ if (i === 0) {
819
+ if (pattern.length > 1) {
820
+ pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1]
821
+ } else {
822
+ pattern[i] = twoStar
823
+ }
824
+ } else if (i === pattern.length - 1) {
825
+ pattern[i-1] += '(?:\\\/|' + twoStar + ')?'
826
+ } else {
827
+ pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1]
828
+ pattern[i+1] = GLOBSTAR
829
+ }
830
+ })
831
+ return pattern.filter(p => p !== GLOBSTAR).join('/')
832
+ }).join('|')
804
833
 
805
834
  // must match entire pattern
806
835
  // ending in a * or ** will make it less strict.
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": "4.0.0",
5
+ "version": "4.2.1",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/isaacs/minimatch.git"
@@ -10,9 +10,10 @@
10
10
  "main": "minimatch.js",
11
11
  "scripts": {
12
12
  "test": "tap",
13
+ "snap": "tap",
13
14
  "preversion": "npm test",
14
15
  "postversion": "npm publish",
15
- "postpublish": "git push origin --all; git push origin --tags"
16
+ "prepublishOnly": "git push origin --follow-tags"
16
17
  },
17
18
  "engines": {
18
19
  "node": ">=10"