minimatch 4.2.2 → 4.2.3

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 (2) hide show
  1. package/minimatch.js +52 -22
  2. package/package.json +1 -1
package/minimatch.js CHANGED
@@ -440,11 +440,23 @@ class Minimatch {
440
440
  let pl
441
441
  let sp
442
442
  // . and .. never match anything that doesn't start with .,
443
- // even when options.dot is set.
444
- const patternStart = pattern.charAt(0) === '.' ? '' // anything
445
- // not (start or / followed by . or .. followed by / or end)
446
- : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
447
- : '(?!\\.)'
443
+ // even when options.dot is set. However, if the pattern
444
+ // starts with ., then traversal patterns can match.
445
+ let dotTravAllowed = pattern.charAt(0) === '.'
446
+ let dotFileAllowed = options.dot || dotTravAllowed
447
+ const patternStart = () =>
448
+ dotTravAllowed
449
+ ? ''
450
+ : dotFileAllowed
451
+ ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
452
+ : '(?!\\.)'
453
+ const subPatternStart = (p) =>
454
+ p.charAt(0) === '.'
455
+ ? ''
456
+ : options.dot
457
+ ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
458
+ : '(?!\\.)'
459
+
448
460
 
449
461
  const clearStateChar = () => {
450
462
  if (stateChar) {
@@ -528,7 +540,7 @@ class Minimatch {
528
540
  if (options.noext) clearStateChar()
529
541
  continue
530
542
 
531
- case '(':
543
+ case '(': {
532
544
  if (inClass) {
533
545
  re += '('
534
546
  continue
@@ -539,46 +551,64 @@ class Minimatch {
539
551
  continue
540
552
  }
541
553
 
542
- patternListStack.push({
554
+ const plEntry = {
543
555
  type: stateChar,
544
556
  start: i - 1,
545
557
  reStart: re.length,
546
558
  open: plTypes[stateChar].open,
547
- close: plTypes[stateChar].close
548
- })
549
- // negation is (?:(?!js)[^/]*)
550
- re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
559
+ close: plTypes[stateChar].close,
560
+ }
561
+ this.debug(this.pattern, '\t', plEntry)
562
+ patternListStack.push(plEntry)
563
+ // negation is (?:(?!(?:js)(?:<rest>))[^/]*)
564
+ re += plEntry.open
565
+ // next entry starts with a dot maybe?
566
+ if (plEntry.start === 0 && plEntry.type !== '!') {
567
+ dotTravAllowed = true
568
+ re += subPatternStart(pattern.slice(i + 1))
569
+ }
551
570
  this.debug('plType %j %j', stateChar, re)
552
571
  stateChar = false
553
- continue
572
+ continue
573
+ }
554
574
 
555
- case ')':
556
- if (inClass || !patternListStack.length) {
575
+ case ')': {
576
+ const plEntry = patternListStack[patternListStack.length - 1]
577
+ if (inClass || !plEntry) {
557
578
  re += '\\)'
558
579
  continue
559
580
  }
581
+ patternListStack.pop()
560
582
 
583
+ // closing an extglob
561
584
  clearStateChar()
562
585
  hasMagic = true
563
- pl = patternListStack.pop()
586
+ pl = plEntry
564
587
  // negation is (?:(?!js)[^/]*)
565
588
  // The others are (?:<pattern>)<type>
566
589
  re += pl.close
567
590
  if (pl.type === '!') {
568
- negativeLists.push(pl)
591
+ negativeLists.push(Object.assign(pl, { reEnd: re.length }))
569
592
  }
570
- pl.reEnd = re.length
571
- continue
593
+ continue
594
+ }
572
595
 
573
- case '|':
574
- if (inClass || !patternListStack.length) {
596
+ case '|': {
597
+ const plEntry = patternListStack[patternListStack.length - 1]
598
+ if (inClass || !plEntry) {
575
599
  re += '\\|'
576
600
  continue
577
601
  }
578
602
 
579
603
  clearStateChar()
580
604
  re += '|'
581
- continue
605
+ // next subpattern can start with a dot?
606
+ if (plEntry.start === 0 && plEntry.type !== '!') {
607
+ dotTravAllowed = true
608
+ re += subPatternStart(pattern.slice(i + 1))
609
+ }
610
+ continue
611
+ }
582
612
 
583
613
  // these are mostly the same in regexp and glob
584
614
  case '[':
@@ -743,7 +773,7 @@ class Minimatch {
743
773
  }
744
774
 
745
775
  if (addPatternStart) {
746
- re = patternStart + re
776
+ re = patternStart() + re
747
777
  }
748
778
 
749
779
  // parsing just a piece of a larger pattern.
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.2.2",
5
+ "version": "4.2.3",
6
6
  "publishConfig": {
7
7
  "tag": "legacy-v4"
8
8
  },