minimatch 4.2.2 → 4.2.4

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 +55 -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) {
@@ -516,6 +528,9 @@ class Minimatch {
516
528
  continue
517
529
  }
518
530
 
531
+ // coalesce consecutive non-globstar * characters
532
+ if (c === '*' && stateChar === '*') continue
533
+
519
534
  // if we already have a stateChar, then it means
520
535
  // that there was something like ** or +? in there.
521
536
  // Handle the stateChar, then proceed with this one.
@@ -528,7 +543,7 @@ class Minimatch {
528
543
  if (options.noext) clearStateChar()
529
544
  continue
530
545
 
531
- case '(':
546
+ case '(': {
532
547
  if (inClass) {
533
548
  re += '('
534
549
  continue
@@ -539,46 +554,64 @@ class Minimatch {
539
554
  continue
540
555
  }
541
556
 
542
- patternListStack.push({
557
+ const plEntry = {
543
558
  type: stateChar,
544
559
  start: i - 1,
545
560
  reStart: re.length,
546
561
  open: plTypes[stateChar].open,
547
- close: plTypes[stateChar].close
548
- })
549
- // negation is (?:(?!js)[^/]*)
550
- re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
562
+ close: plTypes[stateChar].close,
563
+ }
564
+ this.debug(this.pattern, '\t', plEntry)
565
+ patternListStack.push(plEntry)
566
+ // negation is (?:(?!(?:js)(?:<rest>))[^/]*)
567
+ re += plEntry.open
568
+ // next entry starts with a dot maybe?
569
+ if (plEntry.start === 0 && plEntry.type !== '!') {
570
+ dotTravAllowed = true
571
+ re += subPatternStart(pattern.slice(i + 1))
572
+ }
551
573
  this.debug('plType %j %j', stateChar, re)
552
574
  stateChar = false
553
- continue
575
+ continue
576
+ }
554
577
 
555
- case ')':
556
- if (inClass || !patternListStack.length) {
578
+ case ')': {
579
+ const plEntry = patternListStack[patternListStack.length - 1]
580
+ if (inClass || !plEntry) {
557
581
  re += '\\)'
558
582
  continue
559
583
  }
584
+ patternListStack.pop()
560
585
 
586
+ // closing an extglob
561
587
  clearStateChar()
562
588
  hasMagic = true
563
- pl = patternListStack.pop()
589
+ pl = plEntry
564
590
  // negation is (?:(?!js)[^/]*)
565
591
  // The others are (?:<pattern>)<type>
566
592
  re += pl.close
567
593
  if (pl.type === '!') {
568
- negativeLists.push(pl)
594
+ negativeLists.push(Object.assign(pl, { reEnd: re.length }))
569
595
  }
570
- pl.reEnd = re.length
571
- continue
596
+ continue
597
+ }
572
598
 
573
- case '|':
574
- if (inClass || !patternListStack.length) {
599
+ case '|': {
600
+ const plEntry = patternListStack[patternListStack.length - 1]
601
+ if (inClass || !plEntry) {
575
602
  re += '\\|'
576
603
  continue
577
604
  }
578
605
 
579
606
  clearStateChar()
580
607
  re += '|'
581
- continue
608
+ // next subpattern can start with a dot?
609
+ if (plEntry.start === 0 && plEntry.type !== '!') {
610
+ dotTravAllowed = true
611
+ re += subPatternStart(pattern.slice(i + 1))
612
+ }
613
+ continue
614
+ }
582
615
 
583
616
  // these are mostly the same in regexp and glob
584
617
  case '[':
@@ -743,7 +776,7 @@ class Minimatch {
743
776
  }
744
777
 
745
778
  if (addPatternStart) {
746
- re = patternStart + re
779
+ re = patternStart() + re
747
780
  }
748
781
 
749
782
  // 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.4",
6
6
  "publishConfig": {
7
7
  "tag": "legacy-v4"
8
8
  },