Skip to content

Commit 44d60eb

Browse files
committedJul 18, 2023
deps: minimatch@9.0.3
1 parent fc9a843 commit 44d60eb

File tree

5 files changed

+102
-56
lines changed

5 files changed

+102
-56
lines changed
 

‎node_modules/minimatch/dist/cjs/ast.js

+47-24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const isExtglobType = (c) => types.has(c);
1010
// entire string, or just a single path portion, to prevent dots
1111
// and/or traversal patterns, when needed.
1212
// Exts don't need the ^ or / bit, because the root binds that already.
13-
const startNoTraversal = '(?!\\.\\.?(?:$|/))';
13+
const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))';
1414
const startNoDot = '(?!\\.)';
1515
// characters that indicate a start of pattern needs the "no dots" bit,
1616
// because a dot *might* be matched. ( is not in the list, because in
@@ -407,7 +407,8 @@ class AST {
407407
// - Since the start for a join is eg /(?!\.) and the start for a part
408408
// is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
409409
// or start or whatever) and prepend ^ or / at the Regexp construction.
410-
toRegExpSource() {
410+
toRegExpSource(allowDot) {
411+
const dot = allowDot ?? !!this.#options.dot;
411412
if (this.#root === this)
412413
this.#fillNegs();
413414
if (!this.type) {
@@ -416,7 +417,7 @@ class AST {
416417
.map(p => {
417418
const [re, _, hasMagic, uflag] = typeof p === 'string'
418419
? AST.#parseGlob(p, this.#hasMagic, noEmpty)
419-
: p.toRegExpSource();
420+
: p.toRegExpSource(allowDot);
420421
this.#hasMagic = this.#hasMagic || hasMagic;
421422
this.#uflag = this.#uflag || uflag;
422423
return re;
@@ -436,14 +437,14 @@ class AST {
436437
// and prevent that.
437438
const needNoTrav =
438439
// dots are allowed, and the pattern starts with [ or .
439-
(this.#options.dot && aps.has(src.charAt(0))) ||
440+
(dot && aps.has(src.charAt(0))) ||
440441
// the pattern starts with \., and then [ or .
441442
(src.startsWith('\\.') && aps.has(src.charAt(2))) ||
442443
// the pattern starts with \.\., and then [ or .
443444
(src.startsWith('\\.\\.') && aps.has(src.charAt(4)));
444445
// no need to prevent dots if it can't match a dot, or if a
445446
// sub-pattern will be preventing it anyway.
446-
const needNoDot = !this.#options.dot && aps.has(src.charAt(0));
447+
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
447448
start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : '';
448449
}
449450
}
@@ -463,23 +464,13 @@ class AST {
463464
this.#uflag,
464465
];
465466
}
467+
// We need to calculate the body *twice* if it's a repeat pattern
468+
// at the start, once in nodot mode, then again in dot mode, so a
469+
// pattern like *(?) can match 'x.y'
470+
const repeated = this.type === '*' || this.type === '+';
466471
// some kind of extglob
467472
const start = this.type === '!' ? '(?:(?!(?:' : '(?:';
468-
const body = this.#parts
469-
.map(p => {
470-
// extglob ASTs should only contain parent ASTs
471-
/* c8 ignore start */
472-
if (typeof p === 'string') {
473-
throw new Error('string type in extglob ast??');
474-
}
475-
/* c8 ignore stop */
476-
// can ignore hasMagic, because extglobs are already always magic
477-
const [re, _, _hasMagic, uflag] = p.toRegExpSource();
478-
this.#uflag = this.#uflag || uflag;
479-
return re;
480-
})
481-
.filter(p => !(this.isStart() && this.isEnd()) || !!p)
482-
.join('|');
473+
let body = this.#partsToRegExp(dot);
483474
if (this.isStart() && this.isEnd() && !body && this.type !== '!') {
484475
// invalid extglob, has to at least be *something* present, if it's
485476
// the entire path portion.
@@ -489,22 +480,37 @@ class AST {
489480
this.#hasMagic = undefined;
490481
return [s, (0, unescape_js_1.unescape)(this.toString()), false, false];
491482
}
483+
// XXX abstract out this map method
484+
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot
485+
? ''
486+
: this.#partsToRegExp(true);
487+
if (bodyDotAllowed === body) {
488+
bodyDotAllowed = '';
489+
}
490+
if (bodyDotAllowed) {
491+
body = `(?:${body})(?:${bodyDotAllowed})*?`;
492+
}
492493
// an empty !() is exactly equivalent to a starNoEmpty
493494
let final = '';
494495
if (this.type === '!' && this.#emptyExt) {
495-
final =
496-
(this.isStart() && !this.#options.dot ? startNoDot : '') + starNoEmpty;
496+
final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty;
497497
}
498498
else {
499499
const close = this.type === '!'
500500
? // !() must match something,but !(x) can match ''
501501
'))' +
502-
(this.isStart() && !this.#options.dot ? startNoDot : '') +
502+
(this.isStart() && !dot && !allowDot ? startNoDot : '') +
503503
star +
504504
')'
505505
: this.type === '@'
506506
? ')'
507-
: `)${this.type}`;
507+
: this.type === '?'
508+
? ')?'
509+
: this.type === '+' && bodyDotAllowed
510+
? ')'
511+
: this.type === '*' && bodyDotAllowed
512+
? `)?`
513+
: `)${this.type}`;
508514
final = start + body + close;
509515
}
510516
return [
@@ -514,6 +520,23 @@ class AST {
514520
this.#uflag,
515521
];
516522
}
523+
#partsToRegExp(dot) {
524+
return this.#parts
525+
.map(p => {
526+
// extglob ASTs should only contain parent ASTs
527+
/* c8 ignore start */
528+
if (typeof p === 'string') {
529+
throw new Error('string type in extglob ast??');
530+
}
531+
/* c8 ignore stop */
532+
// can ignore hasMagic, because extglobs are already always magic
533+
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
534+
this.#uflag = this.#uflag || uflag;
535+
return re;
536+
})
537+
.filter(p => !(this.isStart() && this.isEnd()) || !!p)
538+
.join('|');
539+
}
517540
static #parseGlob(glob, hasMagic, noEmpty = false) {
518541
let escaping = false;
519542
let re = '';

‎node_modules/minimatch/dist/mjs/ast.js

+47-24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const isExtglobType = (c) => types.has(c);
77
// entire string, or just a single path portion, to prevent dots
88
// and/or traversal patterns, when needed.
99
// Exts don't need the ^ or / bit, because the root binds that already.
10-
const startNoTraversal = '(?!\\.\\.?(?:$|/))';
10+
const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))';
1111
const startNoDot = '(?!\\.)';
1212
// characters that indicate a start of pattern needs the "no dots" bit,
1313
// because a dot *might* be matched. ( is not in the list, because in
@@ -404,7 +404,8 @@ export class AST {
404404
// - Since the start for a join is eg /(?!\.) and the start for a part
405405
// is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
406406
// or start or whatever) and prepend ^ or / at the Regexp construction.
407-
toRegExpSource() {
407+
toRegExpSource(allowDot) {
408+
const dot = allowDot ?? !!this.#options.dot;
408409
if (this.#root === this)
409410
this.#fillNegs();
410411
if (!this.type) {
@@ -413,7 +414,7 @@ export class AST {
413414
.map(p => {
414415
const [re, _, hasMagic, uflag] = typeof p === 'string'
415416
? AST.#parseGlob(p, this.#hasMagic, noEmpty)
416-
: p.toRegExpSource();
417+
: p.toRegExpSource(allowDot);
417418
this.#hasMagic = this.#hasMagic || hasMagic;
418419
this.#uflag = this.#uflag || uflag;
419420
return re;
@@ -433,14 +434,14 @@ export class AST {
433434
// and prevent that.
434435
const needNoTrav =
435436
// dots are allowed, and the pattern starts with [ or .
436-
(this.#options.dot && aps.has(src.charAt(0))) ||
437+
(dot && aps.has(src.charAt(0))) ||
437438
// the pattern starts with \., and then [ or .
438439
(src.startsWith('\\.') && aps.has(src.charAt(2))) ||
439440
// the pattern starts with \.\., and then [ or .
440441
(src.startsWith('\\.\\.') && aps.has(src.charAt(4)));
441442
// no need to prevent dots if it can't match a dot, or if a
442443
// sub-pattern will be preventing it anyway.
443-
const needNoDot = !this.#options.dot && aps.has(src.charAt(0));
444+
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
444445
start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : '';
445446
}
446447
}
@@ -460,23 +461,13 @@ export class AST {
460461
this.#uflag,
461462
];
462463
}
464+
// We need to calculate the body *twice* if it's a repeat pattern
465+
// at the start, once in nodot mode, then again in dot mode, so a
466+
// pattern like *(?) can match 'x.y'
467+
const repeated = this.type === '*' || this.type === '+';
463468
// some kind of extglob
464469
const start = this.type === '!' ? '(?:(?!(?:' : '(?:';
465-
const body = this.#parts
466-
.map(p => {
467-
// extglob ASTs should only contain parent ASTs
468-
/* c8 ignore start */
469-
if (typeof p === 'string') {
470-
throw new Error('string type in extglob ast??');
471-
}
472-
/* c8 ignore stop */
473-
// can ignore hasMagic, because extglobs are already always magic
474-
const [re, _, _hasMagic, uflag] = p.toRegExpSource();
475-
this.#uflag = this.#uflag || uflag;
476-
return re;
477-
})
478-
.filter(p => !(this.isStart() && this.isEnd()) || !!p)
479-
.join('|');
470+
let body = this.#partsToRegExp(dot);
480471
if (this.isStart() && this.isEnd() && !body && this.type !== '!') {
481472
// invalid extglob, has to at least be *something* present, if it's
482473
// the entire path portion.
@@ -486,22 +477,37 @@ export class AST {
486477
this.#hasMagic = undefined;
487478
return [s, unescape(this.toString()), false, false];
488479
}
480+
// XXX abstract out this map method
481+
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot
482+
? ''
483+
: this.#partsToRegExp(true);
484+
if (bodyDotAllowed === body) {
485+
bodyDotAllowed = '';
486+
}
487+
if (bodyDotAllowed) {
488+
body = `(?:${body})(?:${bodyDotAllowed})*?`;
489+
}
489490
// an empty !() is exactly equivalent to a starNoEmpty
490491
let final = '';
491492
if (this.type === '!' && this.#emptyExt) {
492-
final =
493-
(this.isStart() && !this.#options.dot ? startNoDot : '') + starNoEmpty;
493+
final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty;
494494
}
495495
else {
496496
const close = this.type === '!'
497497
? // !() must match something,but !(x) can match ''
498498
'))' +
499-
(this.isStart() && !this.#options.dot ? startNoDot : '') +
499+
(this.isStart() && !dot && !allowDot ? startNoDot : '') +
500500
star +
501501
')'
502502
: this.type === '@'
503503
? ')'
504-
: `)${this.type}`;
504+
: this.type === '?'
505+
? ')?'
506+
: this.type === '+' && bodyDotAllowed
507+
? ')'
508+
: this.type === '*' && bodyDotAllowed
509+
? `)?`
510+
: `)${this.type}`;
505511
final = start + body + close;
506512
}
507513
return [
@@ -511,6 +517,23 @@ export class AST {
511517
this.#uflag,
512518
];
513519
}
520+
#partsToRegExp(dot) {
521+
return this.#parts
522+
.map(p => {
523+
// extglob ASTs should only contain parent ASTs
524+
/* c8 ignore start */
525+
if (typeof p === 'string') {
526+
throw new Error('string type in extglob ast??');
527+
}
528+
/* c8 ignore stop */
529+
// can ignore hasMagic, because extglobs are already always magic
530+
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
531+
this.#uflag = this.#uflag || uflag;
532+
return re;
533+
})
534+
.filter(p => !(this.isStart() && this.isEnd()) || !!p)
535+
.join('|');
536+
}
514537
static #parseGlob(glob, hasMagic, noEmpty = false) {
515538
let escaping = false;
516539
let re = '';

‎node_modules/minimatch/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
33
"name": "minimatch",
44
"description": "a glob matcher in javascript",
5-
"version": "9.0.1",
5+
"version": "9.0.3",
66
"repository": {
77
"type": "git",
88
"url": "git://github.com/isaacs/minimatch.git"
@@ -60,12 +60,12 @@
6060
"devDependencies": {
6161
"@types/brace-expansion": "^1.1.0",
6262
"@types/node": "^18.15.11",
63-
"@types/tap": "^15.0.7",
63+
"@types/tap": "^15.0.8",
6464
"c8": "^7.12.0",
6565
"eslint-config-prettier": "^8.6.0",
6666
"mkdirp": "1",
6767
"prettier": "^2.8.2",
68-
"tap": "^16.3.3",
68+
"tap": "^16.3.7",
6969
"ts-node": "^10.9.1",
7070
"typedoc": "^0.23.21",
7171
"typescript": "^4.9.3"

‎package-lock.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"libnpmteam": "^5.0.3",
124124
"libnpmversion": "^4.0.2",
125125
"make-fetch-happen": "^11.1.1",
126-
"minimatch": "^9.0.0",
126+
"minimatch": "^9.0.3",
127127
"minipass": "^5.0.0",
128128
"minipass-pipeline": "^1.2.4",
129129
"ms": "^2.1.2",
@@ -8981,9 +8981,9 @@
89818981
}
89828982
},
89838983
"node_modules/minimatch": {
8984-
"version": "9.0.1",
8985-
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.1.tgz",
8986-
"integrity": "sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==",
8984+
"version": "9.0.3",
8985+
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz",
8986+
"integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==",
89878987
"inBundle": true,
89888988
"dependencies": {
89898989
"brace-expansion": "^2.0.1"

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"libnpmteam": "^5.0.3",
8989
"libnpmversion": "^4.0.2",
9090
"make-fetch-happen": "^11.1.1",
91-
"minimatch": "^9.0.0",
91+
"minimatch": "^9.0.3",
9292
"minipass": "^5.0.0",
9393
"minipass-pipeline": "^1.2.4",
9494
"ms": "^2.1.2",

0 commit comments

Comments
 (0)
Please sign in to comment.