minimatch 5.1.5 → 5.1.7

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) {
@@ -521,6 +533,9 @@ class Minimatch {
521
533
  continue
522
534
  }
523
535
 
536
+ // coalesce consecutive non-globstar * characters
537
+ if (c === '*' && stateChar === '*') continue
538
+
524
539
  // if we already have a stateChar, then it means
525
540
  // that there was something like ** or +? in there.
526
541
  // Handle the stateChar, then proceed with this one.
@@ -533,7 +548,7 @@ class Minimatch {
533
548
  if (options.noext) clearStateChar()
534
549
  continue
535
550
 
536
- case '(':
551
+ case '(': {
537
552
  if (inClass) {
538
553
  re += '('
539
554
  continue
@@ -544,46 +559,64 @@ class Minimatch {
544
559
  continue
545
560
  }
546
561
 
547
- patternListStack.push({
562
+ const plEntry = {
548
563
  type: stateChar,
549
564
  start: i - 1,
550
565
  reStart: re.length,
551
566
  open: plTypes[stateChar].open,
552
- close: plTypes[stateChar].close
553
- })
554
- // negation is (?:(?!js)[^/]*)
555
- re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
567
+ close: plTypes[stateChar].close,
568
+ }
569
+ this.debug(this.pattern, '\t', plEntry)
570
+ patternListStack.push(plEntry)
571
+ // negation is (?:(?!(?:js)(?:<rest>))[^/]*)
572
+ re += plEntry.open
573
+ // next entry starts with a dot maybe?
574
+ if (plEntry.start === 0 && plEntry.type !== '!') {
575
+ dotTravAllowed = true
576
+ re += subPatternStart(pattern.slice(i + 1))
577
+ }
556
578
  this.debug('plType %j %j', stateChar, re)
557
579
  stateChar = false
558
- continue
580
+ continue
581
+ }
559
582
 
560
- case ')':
561
- if (inClass || !patternListStack.length) {
583
+ case ')': {
584
+ const plEntry = patternListStack[patternListStack.length - 1]
585
+ if (inClass || !plEntry) {
562
586
  re += '\\)'
563
587
  continue
564
588
  }
589
+ patternListStack.pop()
565
590
 
591
+ // closing an extglob
566
592
  clearStateChar()
567
593
  hasMagic = true
568
- pl = patternListStack.pop()
594
+ pl = plEntry
569
595
  // negation is (?:(?!js)[^/]*)
570
596
  // The others are (?:<pattern>)<type>
571
597
  re += pl.close
572
598
  if (pl.type === '!') {
573
- negativeLists.push(pl)
599
+ negativeLists.push(Object.assign(pl, { reEnd: re.length }))
574
600
  }
575
- pl.reEnd = re.length
576
- continue
601
+ continue
602
+ }
577
603
 
578
- case '|':
579
- if (inClass || !patternListStack.length) {
604
+ case '|': {
605
+ const plEntry = patternListStack[patternListStack.length - 1]
606
+ if (inClass || !plEntry) {
580
607
  re += '\\|'
581
608
  continue
582
609
  }
583
610
 
584
611
  clearStateChar()
585
612
  re += '|'
586
- continue
613
+ // next subpattern can start with a dot?
614
+ if (plEntry.start === 0 && plEntry.type !== '!') {
615
+ dotTravAllowed = true
616
+ re += subPatternStart(pattern.slice(i + 1))
617
+ }
618
+ continue
619
+ }
587
620
 
588
621
  // these are mostly the same in regexp and glob
589
622
  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
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "tag": "legacy-v5"
7
7
  },
8
- "version": "5.1.5",
8
+ "version": "5.1.7",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git://github.com/isaacs/minimatch.git"