Socket
Socket
Sign inDemoInstall

minimatch

Package Overview
Dependencies
2
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.4.4 to 8.0.2

dist/cjs/ast.d.ts

3

dist/cjs/index-cjs.d.ts

@@ -10,2 +10,3 @@ declare const _default: {

match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
AST: typeof import("./ast.js").AST;
Minimatch: typeof import("./index.js").Minimatch;

@@ -24,2 +25,3 @@ escape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;

match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
AST: typeof import("./ast.js").AST;
Minimatch: typeof import("./index.js").Minimatch;

@@ -38,2 +40,3 @@ escape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;

match: (list: string[], pattern: string, options?: import("./index.js").MinimatchOptions) => string[];
AST: typeof import("./ast.js").AST;
Minimatch: typeof import("./index.js").Minimatch;

@@ -40,0 +43,0 @@ escape: (s: string, { windowsPathsNoEscape, }?: Pick<import("./index.js").MinimatchOptions, "windowsPathsNoEscape">) => string;

10

dist/cjs/index.d.ts

@@ -0,1 +1,2 @@

import { AST } from './ast.js';
export interface MinimatchOptions {

@@ -32,2 +33,3 @@ nobrace?: boolean;

match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
AST: typeof AST;
Minimatch: typeof Minimatch;

@@ -50,5 +52,4 @@ escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;

};
type SubparseReturn = [string, boolean];
type ParseReturnFiltered = string | MMRegExp | typeof GLOBSTAR;
type ParseReturn = ParseReturnFiltered | false;
export type ParseReturnFiltered = string | MMRegExp | typeof GLOBSTAR;
export type ParseReturn = ParseReturnFiltered | false;
export declare class Minimatch {

@@ -86,3 +87,3 @@ options: MinimatchOptions;

braceExpand(): string[];
parse(pattern: string): ParseReturn | SubparseReturn;
parse(pattern: string): ParseReturn;
makeRe(): false | MMRegExp;

@@ -93,4 +94,5 @@ slashSplit(p: string): string[];

}
export { AST } from './ast.js';
export { escape } from './escape.js';
export { unescape } from './unescape.js';
//# sourceMappingURL=index.d.ts.map

@@ -6,9 +6,10 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.unescape = exports.escape = exports.Minimatch = exports.match = exports.makeRe = exports.braceExpand = exports.defaults = exports.filter = exports.GLOBSTAR = exports.sep = exports.minimatch = void 0;
exports.unescape = exports.escape = exports.AST = exports.Minimatch = exports.match = exports.makeRe = exports.braceExpand = exports.defaults = exports.filter = exports.GLOBSTAR = exports.sep = exports.minimatch = void 0;
const brace_expansion_1 = __importDefault(require("brace-expansion"));
const brace_expressions_js_1 = require("./brace-expressions.js");
const assert_valid_pattern_js_1 = require("./assert-valid-pattern.js");
const ast_js_1 = require("./ast.js");
const escape_js_1 = require("./escape.js");
const unescape_js_1 = require("./unescape.js");
const minimatch = (p, pattern, options = {}) => {
assertValidPattern(pattern);
(0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
// shortcut: comments match nothing.

@@ -89,9 +90,2 @@ if (!options.nocomment && pattern.charAt(0) === '#') {

exports.minimatch.GLOBSTAR = exports.GLOBSTAR;
const plTypes = {
'!': { open: '(?:(?!(?:', close: '))[^/]*?)' },
'?': { open: '(?:', close: ')?' },
'+': { open: '(?:', close: ')+' },
'*': { open: '(?:', close: ')*' },
'@': { open: '(?:', close: ')' },
};
// any single thing other than /

@@ -109,11 +103,2 @@ // don't need to escape / when using new RegExp()

const twoStarNoDot = '(?:(?!(?:\\/|^)\\.).)*?';
// "abc" -> { a:true, b:true, c:true }
const charSet = (s) => s.split('').reduce((set, c) => {
set[c] = true;
return set;
}, {});
// characters that need to be escaped in RegExp.
const reSpecials = charSet('().*{}+?[]^$\\!');
// characters that indicate we have to add the pattern start
const addPatternStartSet = charSet('[.(');
const filter = (pattern, options = {}) => (p) => (0, exports.minimatch)(p, pattern, options);

@@ -138,2 +123,12 @@ exports.filter = filter;

},
AST: class AST extends orig.AST {
/* c8 ignore start */
constructor(type, parent, options = {}) {
super(type, parent, ext(def, options));
}
/* c8 ignore stop */
static fromGlob(pattern, options = {}) {
return orig.AST.fromGlob(pattern, ext(def, options));
}
},
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),

@@ -163,3 +158,3 @@ escape: (s, options = {}) => orig.escape(s, ext(def, options)),

const braceExpand = (pattern, options = {}) => {
assertValidPattern(pattern);
(0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
// Thanks to Yeting Li <https://github.com/yetingli> for

@@ -175,11 +170,2 @@ // improving this regexp to avoid a ReDOS vulnerability.

exports.minimatch.braceExpand = exports.braceExpand;
const MAX_PATTERN_LENGTH = 1024 * 64;
const assertValidPattern = (pattern) => {
if (typeof pattern !== 'string') {
throw new TypeError('invalid pattern');
}
if (pattern.length > MAX_PATTERN_LENGTH) {
throw new TypeError('pattern is too long');
}
};
// parse a component of the expanded set.

@@ -210,3 +196,2 @@ // At this point, no pattern may contain "/" in it

// replace stuff like \* with *
const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;

@@ -233,3 +218,3 @@ const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');

constructor(pattern, options = {}) {
assertValidPattern(pattern);
(0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
options = options || {};

@@ -825,3 +810,3 @@ this.options = options;

parse(pattern) {
assertValidPattern(pattern);
(0, assert_valid_pattern_js_1.assertValidPattern)(pattern);
const options = this.options;

@@ -864,289 +849,4 @@ // shortcuts

}
let re = '';
let hasMagic = false;
let escaping = false;
// ? => one single character
const patternListStack = [];
const negativeLists = [];
let stateChar = false;
let uflag = false;
let pl;
// . and .. never match anything that doesn't start with .,
// even when options.dot is set. However, if the pattern
// starts with ., then traversal patterns can match.
let dotTravAllowed = pattern.charAt(0) === '.';
let dotFileAllowed = options.dot || dotTravAllowed;
const patternStart = () => dotTravAllowed
? ''
: dotFileAllowed
? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
: '(?!\\.)';
const subPatternStart = (p) => p.charAt(0) === '.'
? ''
: options.dot
? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
: '(?!\\.)';
const clearStateChar = () => {
if (stateChar) {
// we had some state-tracking character
// that wasn't consumed by this pass.
switch (stateChar) {
case '*':
re += star;
hasMagic = true;
break;
case '?':
re += qmark;
hasMagic = true;
break;
default:
re += '\\' + stateChar;
break;
}
this.debug('clearStateChar %j %j', stateChar, re);
stateChar = false;
}
};
for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
this.debug('%s\t%s %s %j', pattern, i, re, c);
// skip over any that are escaped.
if (escaping) {
// completely not allowed, even escaped.
// should be impossible.
/* c8 ignore start */
if (c === '/') {
return false;
}
/* c8 ignore stop */
if (reSpecials[c]) {
re += '\\';
}
re += c;
escaping = false;
continue;
}
switch (c) {
// Should already be path-split by now.
/* c8 ignore start */
case '/': {
return false;
}
/* c8 ignore stop */
case '\\':
clearStateChar();
escaping = true;
continue;
// the various stateChar values
// for the "extglob" stuff.
case '?':
case '*':
case '+':
case '@':
case '!':
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
// if we already have a stateChar, then it means
// that there was something like ** or +? in there.
// Handle the stateChar, then proceed with this one.
this.debug('call clearStateChar %j', stateChar);
clearStateChar();
stateChar = c;
// if extglob is disabled, then +(asdf|foo) isn't a thing.
// just clear the statechar *now*, rather than even diving into
// the patternList stuff.
if (options.noext)
clearStateChar();
continue;
case '(': {
if (!stateChar) {
re += '\\(';
continue;
}
const plEntry = {
type: stateChar,
start: i - 1,
reStart: re.length,
open: plTypes[stateChar].open,
close: plTypes[stateChar].close,
};
this.debug(this.pattern, '\t', plEntry);
patternListStack.push(plEntry);
// negation is (?:(?!(?:js)(?:<rest>))[^/]*)
re += plEntry.open;
// next entry starts with a dot maybe?
if (plEntry.start === 0 && plEntry.type !== '!') {
dotTravAllowed = true;
re += subPatternStart(pattern.slice(i + 1));
}
this.debug('plType %j %j', stateChar, re);
stateChar = false;
continue;
}
case ')': {
const plEntry = patternListStack[patternListStack.length - 1];
if (!plEntry) {
re += '\\)';
continue;
}
patternListStack.pop();
// closing an extglob
clearStateChar();
hasMagic = true;
pl = plEntry;
// negation is (?:(?!js)[^/]*)
// The others are (?:<pattern>)<type>
re += pl.close;
if (pl.type === '!') {
negativeLists.push(Object.assign(pl, { reEnd: re.length }));
}
continue;
}
case '|': {
const plEntry = patternListStack[patternListStack.length - 1];
if (!plEntry) {
re += '\\|';
continue;
}
clearStateChar();
re += '|';
// next subpattern can start with a dot?
if (plEntry.start === 0 && plEntry.type !== '!') {
dotTravAllowed = true;
re += subPatternStart(pattern.slice(i + 1));
}
continue;
}
// these are mostly the same in regexp and glob
case '[':
// swallow any state-tracking char before the [
clearStateChar();
const [src, needUflag, consumed, magic] = (0, brace_expressions_js_1.parseClass)(pattern, i);
if (consumed) {
re += src;
uflag = uflag || needUflag;
i += consumed - 1;
hasMagic = hasMagic || magic;
}
else {
re += '\\[';
}
continue;
case ']':
re += '\\' + c;
continue;
default:
// swallow any state char that wasn't consumed
clearStateChar();
re += regExpEscape(c);
break;
} // switch
} // for
// handle the case where we had a +( thing at the *end*
// of the pattern.
// each pattern list stack adds 3 chars, and we need to go through
// and escape any | chars that were passed through as-is for the regexp.
// Go through and escape them, taking care not to double-escape any
// | chars that were already escaped.
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
let tail;
tail = re.slice(pl.reStart + pl.open.length);
this.debug(this.pattern, 'setting tail', re, pl);
// maybe some even number of \, then maybe 1 \, followed by a |
tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
if (!$2) {
// the | isn't already escaped, so escape it.
$2 = '\\';
// should already be done
/* c8 ignore start */
}
/* c8 ignore stop */
// need to escape all those slashes *again*, without escaping the
// one that we need for escaping the | character. As it works out,
// escaping an even number of slashes can be done by simply repeating
// it exactly after itself. That's why this trick works.
//
// I am sorry that you have to see this.
return $1 + $1 + $2 + '|';
});
this.debug('tail=%j\n %s', tail, tail, pl, re);
const t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
hasMagic = true;
re = re.slice(0, pl.reStart) + t + '\\(' + tail;
}
// handle trailing things that only matter at the very end.
clearStateChar();
if (escaping) {
// trailing \\
re += '\\\\';
}
// only need to apply the nodot start if the re starts with
// something that could conceivably capture a dot
const addPatternStart = addPatternStartSet[re.charAt(0)];
// Hack to work around lack of negative lookbehind in JS
// A pattern like: *.!(x).!(y|z) needs to ensure that a name
// like 'a.xyz.yz' doesn't match. So, the first negative
// lookahead, has to look ALL the way ahead, to the end of
// the pattern.
for (let n = negativeLists.length - 1; n > -1; n--) {
const nl = negativeLists[n];
const nlBefore = re.slice(0, nl.reStart);
const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
let nlAfter = re.slice(nl.reEnd);
const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
// Handle nested stuff like *(*.js|!(*.json)), where open parens
// mean that we should *not* include the ) in the bit that is considered
// "after" the negated section.
const closeParensBefore = nlBefore.split(')').length;
const openParensBefore = nlBefore.split('(').length - closeParensBefore;
let cleanAfter = nlAfter;
for (let i = 0; i < openParensBefore; i++) {
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
}
nlAfter = cleanAfter;
const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
}
// if the re is not "" at this point, then we need to make sure
// it doesn't match against an empty path part.
// Otherwise a/* will match a/, which it should not.
if (re !== '' && hasMagic) {
re = '(?=.)' + re;
}
if (addPatternStart) {
re = patternStart() + re;
}
// if it's nocase, and the lcase/uppercase don't match, it's magic
if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
}
// skip the regexp for non-magical patterns
// unescape anything in it, though, so that it'll be
// an exact match against a file etc.
if (!hasMagic) {
return globUnescape(re);
}
const flags = (options.nocase ? 'i' : '') + (uflag ? 'u' : '');
try {
const ext = fastTest
? {
_glob: pattern,
_src: re,
test: fastTest,
}
: {
_glob: pattern,
_src: re,
};
return Object.assign(new RegExp('^' + re + '$', flags), ext);
/* c8 ignore start */
}
catch (er) {
// should be impossible
// If it was an invalid regular expression, then it can't match
// anything. This trick looks for a character after the end of
// the string, which is of course impossible, except in multi-line
// mode, but it's not a /m regex.
this.debug('invalid regexp', er);
return new RegExp('$.');
}
/* c8 ignore stop */
const re = ast_js_1.AST.fromGlob(pattern, this.options).toMMPattern();
return fastTest ? Object.assign(re, { test: fastTest }) : re;
}

@@ -1173,3 +873,3 @@ makeRe() {

: twoStarNoDot;
const flags = options.nocase ? 'i' : '';
const flags = new Set(options.nocase ? ['i'] : []);
// regexpify non-globstar patterns

@@ -1183,7 +883,13 @@ // if ** is only item, then we just do one twoStar

.map(pattern => {
const pp = pattern.map(p => typeof p === 'string'
? regExpEscape(p)
: p === exports.GLOBSTAR
? exports.GLOBSTAR
: p._src);
const pp = pattern.map(p => {
if (p instanceof RegExp) {
for (const f of p.flags.split(''))
flags.add(f);
}
return typeof p === 'string'
? regExpEscape(p)
: p === exports.GLOBSTAR
? exports.GLOBSTAR
: p._src;
});
pp.forEach((p, i) => {

@@ -1214,10 +920,13 @@ const next = pp[i + 1];

.join('|');
// need to wrap in parens if we had more than one thing with |,
// otherwise only the first will be anchored to ^ and the last to $
const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', ''];
// must match entire pattern
// ending in a * or ** will make it less strict.
re = '^(?:' + re + ')$';
re = '^' + open + re + close + '$';
// can match anything, as long as it's not this.
if (this.negate)
re = '^(?!' + re + ').*$';
re = '^(?!' + re + ').+$';
try {
this.regexp = new RegExp(re, flags);
this.regexp = new RegExp(re, [...flags].join(''));
/* c8 ignore start */

@@ -1309,2 +1018,4 @@ }

/* c8 ignore start */
var ast_js_2 = require("./ast.js");
Object.defineProperty(exports, "AST", { enumerable: true, get: function () { return ast_js_2.AST; } });
var escape_js_2 = require("./escape.js");

@@ -1315,2 +1026,3 @@ Object.defineProperty(exports, "escape", { enumerable: true, get: function () { return escape_js_2.escape; } });

/* c8 ignore stop */
exports.minimatch.AST = ast_js_1.AST;
exports.minimatch.Minimatch = Minimatch;

@@ -1317,0 +1029,0 @@ exports.minimatch.escape = escape_js_1.escape;

@@ -0,1 +1,2 @@

import { AST } from './ast.js';
export interface MinimatchOptions {

@@ -32,2 +33,3 @@ nobrace?: boolean;

match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
AST: typeof AST;
Minimatch: typeof Minimatch;

@@ -50,5 +52,4 @@ escape: (s: string, { windowsPathsNoEscape, }?: Pick<MinimatchOptions, "windowsPathsNoEscape">) => string;

};
type SubparseReturn = [string, boolean];
type ParseReturnFiltered = string | MMRegExp | typeof GLOBSTAR;
type ParseReturn = ParseReturnFiltered | false;
export type ParseReturnFiltered = string | MMRegExp | typeof GLOBSTAR;
export type ParseReturn = ParseReturnFiltered | false;
export declare class Minimatch {

@@ -86,3 +87,3 @@ options: MinimatchOptions;

braceExpand(): string[];
parse(pattern: string): ParseReturn | SubparseReturn;
parse(pattern: string): ParseReturn;
makeRe(): false | MMRegExp;

@@ -93,4 +94,5 @@ slashSplit(p: string): string[];

}
export { AST } from './ast.js';
export { escape } from './escape.js';
export { unescape } from './unescape.js';
//# sourceMappingURL=index.d.ts.map
import expand from 'brace-expansion';
import { parseClass } from './brace-expressions.js';
import { assertValidPattern } from './assert-valid-pattern.js';
import { AST } from './ast.js';
import { escape } from './escape.js';

@@ -81,9 +82,2 @@ import { unescape } from './unescape.js';

minimatch.GLOBSTAR = GLOBSTAR;
const plTypes = {
'!': { open: '(?:(?!(?:', close: '))[^/]*?)' },
'?': { open: '(?:', close: ')?' },
'+': { open: '(?:', close: ')+' },
'*': { open: '(?:', close: ')*' },
'@': { open: '(?:', close: ')' },
};
// any single thing other than /

@@ -101,11 +95,2 @@ // don't need to escape / when using new RegExp()

const twoStarNoDot = '(?:(?!(?:\\/|^)\\.).)*?';
// "abc" -> { a:true, b:true, c:true }
const charSet = (s) => s.split('').reduce((set, c) => {
set[c] = true;
return set;
}, {});
// characters that need to be escaped in RegExp.
const reSpecials = charSet('().*{}+?[]^$\\!');
// characters that indicate we have to add the pattern start
const addPatternStartSet = charSet('[.(');
export const filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);

@@ -129,2 +114,12 @@ minimatch.filter = filter;

},
AST: class AST extends orig.AST {
/* c8 ignore start */
constructor(type, parent, options = {}) {
super(type, parent, ext(def, options));
}
/* c8 ignore stop */
static fromGlob(pattern, options = {}) {
return orig.AST.fromGlob(pattern, ext(def, options));
}
},
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),

@@ -163,11 +158,2 @@ escape: (s, options = {}) => orig.escape(s, ext(def, options)),

minimatch.braceExpand = braceExpand;
const MAX_PATTERN_LENGTH = 1024 * 64;
const assertValidPattern = (pattern) => {
if (typeof pattern !== 'string') {
throw new TypeError('invalid pattern');
}
if (pattern.length > MAX_PATTERN_LENGTH) {
throw new TypeError('pattern is too long');
}
};
// parse a component of the expanded set.

@@ -196,3 +182,2 @@ // At this point, no pattern may contain "/" in it

// replace stuff like \* with *
const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;

@@ -848,289 +833,4 @@ const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');

}
let re = '';
let hasMagic = false;
let escaping = false;
// ? => one single character
const patternListStack = [];
const negativeLists = [];
let stateChar = false;
let uflag = false;
let pl;
// . and .. never match anything that doesn't start with .,
// even when options.dot is set. However, if the pattern
// starts with ., then traversal patterns can match.
let dotTravAllowed = pattern.charAt(0) === '.';
let dotFileAllowed = options.dot || dotTravAllowed;
const patternStart = () => dotTravAllowed
? ''
: dotFileAllowed
? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
: '(?!\\.)';
const subPatternStart = (p) => p.charAt(0) === '.'
? ''
: options.dot
? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
: '(?!\\.)';
const clearStateChar = () => {
if (stateChar) {
// we had some state-tracking character
// that wasn't consumed by this pass.
switch (stateChar) {
case '*':
re += star;
hasMagic = true;
break;
case '?':
re += qmark;
hasMagic = true;
break;
default:
re += '\\' + stateChar;
break;
}
this.debug('clearStateChar %j %j', stateChar, re);
stateChar = false;
}
};
for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
this.debug('%s\t%s %s %j', pattern, i, re, c);
// skip over any that are escaped.
if (escaping) {
// completely not allowed, even escaped.
// should be impossible.
/* c8 ignore start */
if (c === '/') {
return false;
}
/* c8 ignore stop */
if (reSpecials[c]) {
re += '\\';
}
re += c;
escaping = false;
continue;
}
switch (c) {
// Should already be path-split by now.
/* c8 ignore start */
case '/': {
return false;
}
/* c8 ignore stop */
case '\\':
clearStateChar();
escaping = true;
continue;
// the various stateChar values
// for the "extglob" stuff.
case '?':
case '*':
case '+':
case '@':
case '!':
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
// if we already have a stateChar, then it means
// that there was something like ** or +? in there.
// Handle the stateChar, then proceed with this one.
this.debug('call clearStateChar %j', stateChar);
clearStateChar();
stateChar = c;
// if extglob is disabled, then +(asdf|foo) isn't a thing.
// just clear the statechar *now*, rather than even diving into
// the patternList stuff.
if (options.noext)
clearStateChar();
continue;
case '(': {
if (!stateChar) {
re += '\\(';
continue;
}
const plEntry = {
type: stateChar,
start: i - 1,
reStart: re.length,
open: plTypes[stateChar].open,
close: plTypes[stateChar].close,
};
this.debug(this.pattern, '\t', plEntry);
patternListStack.push(plEntry);
// negation is (?:(?!(?:js)(?:<rest>))[^/]*)
re += plEntry.open;
// next entry starts with a dot maybe?
if (plEntry.start === 0 && plEntry.type !== '!') {
dotTravAllowed = true;
re += subPatternStart(pattern.slice(i + 1));
}
this.debug('plType %j %j', stateChar, re);
stateChar = false;
continue;
}
case ')': {
const plEntry = patternListStack[patternListStack.length - 1];
if (!plEntry) {
re += '\\)';
continue;
}
patternListStack.pop();
// closing an extglob
clearStateChar();
hasMagic = true;
pl = plEntry;
// negation is (?:(?!js)[^/]*)
// The others are (?:<pattern>)<type>
re += pl.close;
if (pl.type === '!') {
negativeLists.push(Object.assign(pl, { reEnd: re.length }));
}
continue;
}
case '|': {
const plEntry = patternListStack[patternListStack.length - 1];
if (!plEntry) {
re += '\\|';
continue;
}
clearStateChar();
re += '|';
// next subpattern can start with a dot?
if (plEntry.start === 0 && plEntry.type !== '!') {
dotTravAllowed = true;
re += subPatternStart(pattern.slice(i + 1));
}
continue;
}
// these are mostly the same in regexp and glob
case '[':
// swallow any state-tracking char before the [
clearStateChar();
const [src, needUflag, consumed, magic] = parseClass(pattern, i);
if (consumed) {
re += src;
uflag = uflag || needUflag;
i += consumed - 1;
hasMagic = hasMagic || magic;
}
else {
re += '\\[';
}
continue;
case ']':
re += '\\' + c;
continue;
default:
// swallow any state char that wasn't consumed
clearStateChar();
re += regExpEscape(c);
break;
} // switch
} // for
// handle the case where we had a +( thing at the *end*
// of the pattern.
// each pattern list stack adds 3 chars, and we need to go through
// and escape any | chars that were passed through as-is for the regexp.
// Go through and escape them, taking care not to double-escape any
// | chars that were already escaped.
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
let tail;
tail = re.slice(pl.reStart + pl.open.length);
this.debug(this.pattern, 'setting tail', re, pl);
// maybe some even number of \, then maybe 1 \, followed by a |
tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
if (!$2) {
// the | isn't already escaped, so escape it.
$2 = '\\';
// should already be done
/* c8 ignore start */
}
/* c8 ignore stop */
// need to escape all those slashes *again*, without escaping the
// one that we need for escaping the | character. As it works out,
// escaping an even number of slashes can be done by simply repeating
// it exactly after itself. That's why this trick works.
//
// I am sorry that you have to see this.
return $1 + $1 + $2 + '|';
});
this.debug('tail=%j\n %s', tail, tail, pl, re);
const t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
hasMagic = true;
re = re.slice(0, pl.reStart) + t + '\\(' + tail;
}
// handle trailing things that only matter at the very end.
clearStateChar();
if (escaping) {
// trailing \\
re += '\\\\';
}
// only need to apply the nodot start if the re starts with
// something that could conceivably capture a dot
const addPatternStart = addPatternStartSet[re.charAt(0)];
// Hack to work around lack of negative lookbehind in JS
// A pattern like: *.!(x).!(y|z) needs to ensure that a name
// like 'a.xyz.yz' doesn't match. So, the first negative
// lookahead, has to look ALL the way ahead, to the end of
// the pattern.
for (let n = negativeLists.length - 1; n > -1; n--) {
const nl = negativeLists[n];
const nlBefore = re.slice(0, nl.reStart);
const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
let nlAfter = re.slice(nl.reEnd);
const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
// Handle nested stuff like *(*.js|!(*.json)), where open parens
// mean that we should *not* include the ) in the bit that is considered
// "after" the negated section.
const closeParensBefore = nlBefore.split(')').length;
const openParensBefore = nlBefore.split('(').length - closeParensBefore;
let cleanAfter = nlAfter;
for (let i = 0; i < openParensBefore; i++) {
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
}
nlAfter = cleanAfter;
const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
}
// if the re is not "" at this point, then we need to make sure
// it doesn't match against an empty path part.
// Otherwise a/* will match a/, which it should not.
if (re !== '' && hasMagic) {
re = '(?=.)' + re;
}
if (addPatternStart) {
re = patternStart() + re;
}
// if it's nocase, and the lcase/uppercase don't match, it's magic
if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
}
// skip the regexp for non-magical patterns
// unescape anything in it, though, so that it'll be
// an exact match against a file etc.
if (!hasMagic) {
return globUnescape(re);
}
const flags = (options.nocase ? 'i' : '') + (uflag ? 'u' : '');
try {
const ext = fastTest
? {
_glob: pattern,
_src: re,
test: fastTest,
}
: {
_glob: pattern,
_src: re,
};
return Object.assign(new RegExp('^' + re + '$', flags), ext);
/* c8 ignore start */
}
catch (er) {
// should be impossible
// If it was an invalid regular expression, then it can't match
// anything. This trick looks for a character after the end of
// the string, which is of course impossible, except in multi-line
// mode, but it's not a /m regex.
this.debug('invalid regexp', er);
return new RegExp('$.');
}
/* c8 ignore stop */
const re = AST.fromGlob(pattern, this.options).toMMPattern();
return fastTest ? Object.assign(re, { test: fastTest }) : re;
}

@@ -1157,3 +857,3 @@ makeRe() {

: twoStarNoDot;
const flags = options.nocase ? 'i' : '';
const flags = new Set(options.nocase ? ['i'] : []);
// regexpify non-globstar patterns

@@ -1167,7 +867,13 @@ // if ** is only item, then we just do one twoStar

.map(pattern => {
const pp = pattern.map(p => typeof p === 'string'
? regExpEscape(p)
: p === GLOBSTAR
? GLOBSTAR
: p._src);
const pp = pattern.map(p => {
if (p instanceof RegExp) {
for (const f of p.flags.split(''))
flags.add(f);
}
return typeof p === 'string'
? regExpEscape(p)
: p === GLOBSTAR
? GLOBSTAR
: p._src;
});
pp.forEach((p, i) => {

@@ -1198,10 +904,13 @@ const next = pp[i + 1];

.join('|');
// need to wrap in parens if we had more than one thing with |,
// otherwise only the first will be anchored to ^ and the last to $
const [open, close] = set.length > 1 ? ['(?:', ')'] : ['', ''];
// must match entire pattern
// ending in a * or ** will make it less strict.
re = '^(?:' + re + ')$';
re = '^' + open + re + close + '$';
// can match anything, as long as it's not this.
if (this.negate)
re = '^(?!' + re + ').*$';
re = '^(?!' + re + ').+$';
try {
this.regexp = new RegExp(re, flags);
this.regexp = new RegExp(re, [...flags].join(''));
/* c8 ignore start */

@@ -1292,5 +1001,7 @@ }

/* c8 ignore start */
export { AST } from './ast.js';
export { escape } from './escape.js';
export { unescape } from './unescape.js';
/* c8 ignore stop */
minimatch.AST = AST;
minimatch.Minimatch = Minimatch;

@@ -1297,0 +1008,0 @@ minimatch.escape = escape;

@@ -5,3 +5,3 @@ {

"description": "a glob matcher in javascript",
"version": "7.4.4",
"version": "8.0.2",
"repository": {

@@ -56,3 +56,3 @@ "type": "git",

"engines": {
"node": ">=10"
"node": ">=16 || 14 >=14.17"
},

@@ -64,3 +64,3 @@ "dependencies": {

"@types/brace-expansion": "^1.1.0",
"@types/node": "^18.11.9",
"@types/node": "^18.15.11",
"@types/tap": "^15.0.7",

@@ -67,0 +67,0 @@ "c8": "^7.12.0",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc