minimatch
Advanced tools
Comparing version 9.0.0 to 9.0.3
@@ -17,9 +17,4 @@ import { MinimatchOptions, MMRegExp } from './index.js'; | ||
toMMPattern(): MMRegExp | string; | ||
toRegExpSource(): [ | ||
re: string, | ||
body: string, | ||
hasMagic: boolean, | ||
uflag: boolean | ||
]; | ||
toRegExpSource(allowDot?: boolean): [re: string, body: string, hasMagic: boolean, uflag: boolean]; | ||
} | ||
//# sourceMappingURL=ast.d.ts.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
// Exts don't need the ^ or / bit, because the root binds that already. | ||
const startNoTraversal = '(?!\\.\\.?(?:$|/))'; | ||
const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))'; | ||
const startNoDot = '(?!\\.)'; | ||
@@ -411,3 +411,4 @@ // characters that indicate a start of pattern needs the "no dots" bit, | ||
// or start or whatever) and prepend ^ or / at the Regexp construction. | ||
toRegExpSource() { | ||
toRegExpSource(allowDot) { | ||
const dot = allowDot ?? !!this.#options.dot; | ||
if (this.#root === this) | ||
@@ -421,3 +422,3 @@ this.#fillNegs(); | ||
? AST.#parseGlob(p, this.#hasMagic, noEmpty) | ||
: p.toRegExpSource(); | ||
: p.toRegExpSource(allowDot); | ||
this.#hasMagic = this.#hasMagic || hasMagic; | ||
@@ -442,3 +443,3 @@ this.#uflag = this.#uflag || uflag; | ||
// dots are allowed, and the pattern starts with [ or . | ||
(this.#options.dot && aps.has(src.charAt(0))) || | ||
(dot && aps.has(src.charAt(0))) || | ||
// the pattern starts with \., and then [ or . | ||
@@ -450,3 +451,3 @@ (src.startsWith('\\.') && aps.has(src.charAt(2))) || | ||
// sub-pattern will be preventing it anyway. | ||
const needNoDot = !this.#options.dot && aps.has(src.charAt(0)); | ||
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0)); | ||
start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : ''; | ||
@@ -471,19 +472,9 @@ } | ||
} | ||
// We need to calculate the body *twice* if it's a repeat pattern | ||
// at the start, once in nodot mode, then again in dot mode, so a | ||
// pattern like *(?) can match 'x.y' | ||
const repeated = this.type === '*' || this.type === '+'; | ||
// some kind of extglob | ||
const start = this.type === '!' ? '(?:(?!(?:' : '(?:'; | ||
const body = this.#parts | ||
.map(p => { | ||
// extglob ASTs should only contain parent ASTs | ||
/* c8 ignore start */ | ||
if (typeof p === 'string') { | ||
throw new Error('string type in extglob ast??'); | ||
} | ||
/* c8 ignore stop */ | ||
// can ignore hasMagic, because extglobs are already always magic | ||
const [re, _, _hasMagic, uflag] = p.toRegExpSource(); | ||
this.#uflag = this.#uflag || uflag; | ||
return re; | ||
}) | ||
.filter(p => !(this.isStart() && this.isEnd()) || !!p) | ||
.join('|'); | ||
let body = this.#partsToRegExp(dot); | ||
if (this.isStart() && this.isEnd() && !body && this.type !== '!') { | ||
@@ -498,7 +489,16 @@ // invalid extglob, has to at least be *something* present, if it's | ||
} | ||
// XXX abstract out this map method | ||
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot | ||
? '' | ||
: this.#partsToRegExp(true); | ||
if (bodyDotAllowed === body) { | ||
bodyDotAllowed = ''; | ||
} | ||
if (bodyDotAllowed) { | ||
body = `(?:${body})(?:${bodyDotAllowed})*?`; | ||
} | ||
// an empty !() is exactly equivalent to a starNoEmpty | ||
let final = ''; | ||
if (this.type === '!' && this.#emptyExt) { | ||
final = | ||
(this.isStart() && !this.#options.dot ? startNoDot : '') + starNoEmpty; | ||
final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty; | ||
} | ||
@@ -509,3 +509,3 @@ else { | ||
'))' + | ||
(this.isStart() && !this.#options.dot ? startNoDot : '') + | ||
(this.isStart() && !dot && !allowDot ? startNoDot : '') + | ||
star + | ||
@@ -515,3 +515,9 @@ ')' | ||
? ')' | ||
: `)${this.type}`; | ||
: this.type === '?' | ||
? ')?' | ||
: this.type === '+' && bodyDotAllowed | ||
? ')' | ||
: this.type === '*' && bodyDotAllowed | ||
? `)?` | ||
: `)${this.type}`; | ||
final = start + body + close; | ||
@@ -526,2 +532,19 @@ } | ||
} | ||
#partsToRegExp(dot) { | ||
return this.#parts | ||
.map(p => { | ||
// extglob ASTs should only contain parent ASTs | ||
/* c8 ignore start */ | ||
if (typeof p === 'string') { | ||
throw new Error('string type in extglob ast??'); | ||
} | ||
/* c8 ignore stop */ | ||
// can ignore hasMagic, because extglobs are already always magic | ||
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot); | ||
this.#uflag = this.#uflag || uflag; | ||
return re; | ||
}) | ||
.filter(p => !(this.isStart() && this.isEnd()) || !!p) | ||
.join('|'); | ||
} | ||
static #parseGlob(glob, hasMagic, noEmpty = false) { | ||
@@ -528,0 +551,0 @@ let escaping = false; |
@@ -611,11 +611,15 @@ "use strict"; | ||
const options = this.options; | ||
// a UNC pattern like //?/c:/* can match a path like c:/x | ||
// and vice versa | ||
// UNC paths like //?/X:/... can match X:/... and vice versa | ||
// Drive letters in absolute drive or unc paths are always compared | ||
// case-insensitively. | ||
if (this.isWindows) { | ||
const fileUNC = file[0] === '' && | ||
const fileDrive = typeof file[0] === 'string' && /^[a-z]:$/i.test(file[0]); | ||
const fileUNC = !fileDrive && | ||
file[0] === '' && | ||
file[1] === '' && | ||
file[2] === '?' && | ||
typeof file[3] === 'string' && | ||
/^[a-z]:$/i.test(file[3]); | ||
const patternUNC = pattern[0] === '' && | ||
const patternDrive = typeof pattern[0] === 'string' && /^[a-z]:$/i.test(pattern[0]); | ||
const patternUNC = !patternDrive && | ||
pattern[0] === '' && | ||
pattern[1] === '' && | ||
@@ -625,24 +629,16 @@ pattern[2] === '?' && | ||
/^[a-z]:$/i.test(pattern[3]); | ||
if (fileUNC && patternUNC) { | ||
const fd = file[3]; | ||
const pd = pattern[3]; | ||
const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined; | ||
const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined; | ||
if (typeof fdi === 'number' && typeof pdi === 'number') { | ||
const [fd, pd] = [file[fdi], pattern[pdi]]; | ||
if (fd.toLowerCase() === pd.toLowerCase()) { | ||
file[3] = pd; | ||
pattern[pdi] = fd; | ||
if (pdi > fdi) { | ||
pattern = pattern.slice(pdi); | ||
} | ||
else if (fdi > pdi) { | ||
file = file.slice(fdi); | ||
} | ||
} | ||
} | ||
else if (patternUNC && typeof file[0] === 'string') { | ||
const pd = pattern[3]; | ||
const fd = file[0]; | ||
if (pd.toLowerCase() === fd.toLowerCase()) { | ||
pattern[3] = fd; | ||
pattern = pattern.slice(3); | ||
} | ||
} | ||
else if (fileUNC && typeof pattern[0] === 'string') { | ||
const fd = file[3]; | ||
if (fd.toLowerCase() === pattern[0].toLowerCase()) { | ||
pattern[0] = fd; | ||
file = file.slice(3); | ||
} | ||
} | ||
} | ||
@@ -649,0 +645,0 @@ // resolve and reduce . and .. portions in the file as well. |
@@ -17,9 +17,4 @@ import { MinimatchOptions, MMRegExp } from './index.js'; | ||
toMMPattern(): MMRegExp | string; | ||
toRegExpSource(): [ | ||
re: string, | ||
body: string, | ||
hasMagic: boolean, | ||
uflag: boolean | ||
]; | ||
toRegExpSource(allowDot?: boolean): [re: string, body: string, hasMagic: boolean, uflag: boolean]; | ||
} | ||
//# sourceMappingURL=ast.d.ts.map |
@@ -10,3 +10,3 @@ // parse a single path portion | ||
// Exts don't need the ^ or / bit, because the root binds that already. | ||
const startNoTraversal = '(?!\\.\\.?(?:$|/))'; | ||
const startNoTraversal = '(?!(?:^|/)\\.\\.?(?:$|/))'; | ||
const startNoDot = '(?!\\.)'; | ||
@@ -408,3 +408,4 @@ // characters that indicate a start of pattern needs the "no dots" bit, | ||
// or start or whatever) and prepend ^ or / at the Regexp construction. | ||
toRegExpSource() { | ||
toRegExpSource(allowDot) { | ||
const dot = allowDot ?? !!this.#options.dot; | ||
if (this.#root === this) | ||
@@ -418,3 +419,3 @@ this.#fillNegs(); | ||
? AST.#parseGlob(p, this.#hasMagic, noEmpty) | ||
: p.toRegExpSource(); | ||
: p.toRegExpSource(allowDot); | ||
this.#hasMagic = this.#hasMagic || hasMagic; | ||
@@ -439,3 +440,3 @@ this.#uflag = this.#uflag || uflag; | ||
// dots are allowed, and the pattern starts with [ or . | ||
(this.#options.dot && aps.has(src.charAt(0))) || | ||
(dot && aps.has(src.charAt(0))) || | ||
// the pattern starts with \., and then [ or . | ||
@@ -447,3 +448,3 @@ (src.startsWith('\\.') && aps.has(src.charAt(2))) || | ||
// sub-pattern will be preventing it anyway. | ||
const needNoDot = !this.#options.dot && aps.has(src.charAt(0)); | ||
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0)); | ||
start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : ''; | ||
@@ -468,19 +469,9 @@ } | ||
} | ||
// We need to calculate the body *twice* if it's a repeat pattern | ||
// at the start, once in nodot mode, then again in dot mode, so a | ||
// pattern like *(?) can match 'x.y' | ||
const repeated = this.type === '*' || this.type === '+'; | ||
// some kind of extglob | ||
const start = this.type === '!' ? '(?:(?!(?:' : '(?:'; | ||
const body = this.#parts | ||
.map(p => { | ||
// extglob ASTs should only contain parent ASTs | ||
/* c8 ignore start */ | ||
if (typeof p === 'string') { | ||
throw new Error('string type in extglob ast??'); | ||
} | ||
/* c8 ignore stop */ | ||
// can ignore hasMagic, because extglobs are already always magic | ||
const [re, _, _hasMagic, uflag] = p.toRegExpSource(); | ||
this.#uflag = this.#uflag || uflag; | ||
return re; | ||
}) | ||
.filter(p => !(this.isStart() && this.isEnd()) || !!p) | ||
.join('|'); | ||
let body = this.#partsToRegExp(dot); | ||
if (this.isStart() && this.isEnd() && !body && this.type !== '!') { | ||
@@ -495,7 +486,16 @@ // invalid extglob, has to at least be *something* present, if it's | ||
} | ||
// XXX abstract out this map method | ||
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot | ||
? '' | ||
: this.#partsToRegExp(true); | ||
if (bodyDotAllowed === body) { | ||
bodyDotAllowed = ''; | ||
} | ||
if (bodyDotAllowed) { | ||
body = `(?:${body})(?:${bodyDotAllowed})*?`; | ||
} | ||
// an empty !() is exactly equivalent to a starNoEmpty | ||
let final = ''; | ||
if (this.type === '!' && this.#emptyExt) { | ||
final = | ||
(this.isStart() && !this.#options.dot ? startNoDot : '') + starNoEmpty; | ||
final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty; | ||
} | ||
@@ -506,3 +506,3 @@ else { | ||
'))' + | ||
(this.isStart() && !this.#options.dot ? startNoDot : '') + | ||
(this.isStart() && !dot && !allowDot ? startNoDot : '') + | ||
star + | ||
@@ -512,3 +512,9 @@ ')' | ||
? ')' | ||
: `)${this.type}`; | ||
: this.type === '?' | ||
? ')?' | ||
: this.type === '+' && bodyDotAllowed | ||
? ')' | ||
: this.type === '*' && bodyDotAllowed | ||
? `)?` | ||
: `)${this.type}`; | ||
final = start + body + close; | ||
@@ -523,2 +529,19 @@ } | ||
} | ||
#partsToRegExp(dot) { | ||
return this.#parts | ||
.map(p => { | ||
// extglob ASTs should only contain parent ASTs | ||
/* c8 ignore start */ | ||
if (typeof p === 'string') { | ||
throw new Error('string type in extglob ast??'); | ||
} | ||
/* c8 ignore stop */ | ||
// can ignore hasMagic, because extglobs are already always magic | ||
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot); | ||
this.#uflag = this.#uflag || uflag; | ||
return re; | ||
}) | ||
.filter(p => !(this.isStart() && this.isEnd()) || !!p) | ||
.join('|'); | ||
} | ||
static #parseGlob(glob, hasMagic, noEmpty = false) { | ||
@@ -525,0 +548,0 @@ let escaping = false; |
@@ -599,11 +599,15 @@ import expand from 'brace-expansion'; | ||
const options = this.options; | ||
// a UNC pattern like //?/c:/* can match a path like c:/x | ||
// and vice versa | ||
// UNC paths like //?/X:/... can match X:/... and vice versa | ||
// Drive letters in absolute drive or unc paths are always compared | ||
// case-insensitively. | ||
if (this.isWindows) { | ||
const fileUNC = file[0] === '' && | ||
const fileDrive = typeof file[0] === 'string' && /^[a-z]:$/i.test(file[0]); | ||
const fileUNC = !fileDrive && | ||
file[0] === '' && | ||
file[1] === '' && | ||
file[2] === '?' && | ||
typeof file[3] === 'string' && | ||
/^[a-z]:$/i.test(file[3]); | ||
const patternUNC = pattern[0] === '' && | ||
const patternDrive = typeof pattern[0] === 'string' && /^[a-z]:$/i.test(pattern[0]); | ||
const patternUNC = !patternDrive && | ||
pattern[0] === '' && | ||
pattern[1] === '' && | ||
@@ -613,24 +617,16 @@ pattern[2] === '?' && | ||
/^[a-z]:$/i.test(pattern[3]); | ||
if (fileUNC && patternUNC) { | ||
const fd = file[3]; | ||
const pd = pattern[3]; | ||
const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined; | ||
const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined; | ||
if (typeof fdi === 'number' && typeof pdi === 'number') { | ||
const [fd, pd] = [file[fdi], pattern[pdi]]; | ||
if (fd.toLowerCase() === pd.toLowerCase()) { | ||
file[3] = pd; | ||
pattern[pdi] = fd; | ||
if (pdi > fdi) { | ||
pattern = pattern.slice(pdi); | ||
} | ||
else if (fdi > pdi) { | ||
file = file.slice(fdi); | ||
} | ||
} | ||
} | ||
else if (patternUNC && typeof file[0] === 'string') { | ||
const pd = pattern[3]; | ||
const fd = file[0]; | ||
if (pd.toLowerCase() === fd.toLowerCase()) { | ||
pattern[3] = fd; | ||
pattern = pattern.slice(3); | ||
} | ||
} | ||
else if (fileUNC && typeof pattern[0] === 'string') { | ||
const fd = file[3]; | ||
if (fd.toLowerCase() === pattern[0].toLowerCase()) { | ||
pattern[0] = fd; | ||
file = file.slice(3); | ||
} | ||
} | ||
} | ||
@@ -637,0 +633,0 @@ // resolve and reduce . and .. portions in the file as well. |
@@ -5,3 +5,3 @@ { | ||
"description": "a glob matcher in javascript", | ||
"version": "9.0.0", | ||
"version": "9.0.3", | ||
"repository": { | ||
@@ -64,3 +64,3 @@ "type": "git", | ||
"@types/node": "^18.15.11", | ||
"@types/tap": "^15.0.7", | ||
"@types/tap": "^15.0.8", | ||
"c8": "^7.12.0", | ||
@@ -70,3 +70,3 @@ "eslint-config-prettier": "^8.6.0", | ||
"prettier": "^2.8.2", | ||
"tap": "^16.3.3", | ||
"tap": "^16.3.7", | ||
"ts-node": "^10.9.1", | ||
@@ -73,0 +73,0 @@ "typedoc": "^0.23.21", |
@@ -258,3 +258,3 @@ # minimatch | ||
If the pattern contains brace expansions, such as `a{b,c}d`, but | ||
no other magic characters, then the `Minipass.hasMagic()` method | ||
no other magic characters, then the `Minimatch.hasMagic()` method | ||
will return `false` by default. When this option set, it will | ||
@@ -261,0 +261,0 @@ return `true` for brace expansion as well as other magic glob |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
433705
3868