minimatch 7.2.0 → 7.3.0
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.
- package/README.md +10 -1
- package/dist/cjs/brace-expressions.d.ts +1 -0
- package/dist/cjs/brace-expressions.js +141 -0
- package/dist/cjs/brace-expressions.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +45 -114
- package/dist/cjs/index.js.map +1 -1
- package/dist/mjs/brace-expressions.d.ts +1 -0
- package/dist/mjs/brace-expressions.js +137 -0
- package/dist/mjs/brace-expressions.js.map +1 -0
- package/dist/mjs/index.d.ts +1 -2
- package/dist/mjs/index.js +45 -114
- package/dist/mjs/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,11 +32,20 @@ Supports these glob features:
|
|
|
32
32
|
- Brace Expansion
|
|
33
33
|
- Extended glob matching
|
|
34
34
|
- "Globstar" `**` matching
|
|
35
|
+
- [Posix character
|
|
36
|
+
classes](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html),
|
|
37
|
+
like `[[:alpha:]]`, supporting the full range of Unicode
|
|
38
|
+
characters. For example, `[[:alpha:]]` will match against
|
|
39
|
+
`'é'`, though `[a-zA-Z]` will not. Collating symbol and set
|
|
40
|
+
matching is not supported, so `[[=e=]]` will _not_ match `'é'`
|
|
41
|
+
and `[[.ch.]]` will not match `'ch'` in locales where `ch` is
|
|
42
|
+
considered a single character.
|
|
35
43
|
|
|
36
44
|
See:
|
|
37
45
|
|
|
38
46
|
- `man sh`
|
|
39
|
-
- `man bash`
|
|
47
|
+
- `man bash` [Pattern
|
|
48
|
+
Matching](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html)
|
|
40
49
|
- `man 3 fnmatch`
|
|
41
50
|
- `man 5 gitignore`
|
|
42
51
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parseClass: (glob: string, position: number) => [string, boolean, number];
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// translate the various posix character classes into unicode properties
|
|
3
|
+
// this works across all unicode locales
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.parseClass = void 0;
|
|
6
|
+
// { <posix class>: [<translation>, /u flag required, negated]
|
|
7
|
+
const posixClasses = {
|
|
8
|
+
'[:alnum:]': ['\\p{L}\\p{Nl}\\p{Nd}', true],
|
|
9
|
+
'[:alpha:]': ['\\p{L}\\p{Nl}', true],
|
|
10
|
+
'[:ascii:]': ['\\x' + '00-\\x' + '7f', false],
|
|
11
|
+
'[:blank:]': ['\\p{Zs}\\t', true],
|
|
12
|
+
'[:cntrl:]': ['\\p{Cc}', true],
|
|
13
|
+
'[:digit:]': ['\\p{Nd}', true],
|
|
14
|
+
'[:graph:]': ['\\p{Z}\\p{C}', true, true],
|
|
15
|
+
'[:lower:]': ['\\p{Ll}', true],
|
|
16
|
+
'[:print:]': ['\\p{C}', true],
|
|
17
|
+
'[:punct:]': ['\\p{P}', true],
|
|
18
|
+
'[:space:]': ['\\p{Z}\\t\\r\\n\\v\\f', true],
|
|
19
|
+
'[:upper:]': ['\\p{Lu}', true],
|
|
20
|
+
'[:word:]': ['\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}', true],
|
|
21
|
+
'[:xdigit:]': ['A-Fa-f0-9', false],
|
|
22
|
+
};
|
|
23
|
+
// only need to escape a few things inside of brace expressions
|
|
24
|
+
const regExpEscape = (s) => s.replace(/[[\]\\-]/g, '\\$&');
|
|
25
|
+
const rangesToString = (ranges) => {
|
|
26
|
+
return (ranges
|
|
27
|
+
// .map(r => r.replace(/[[\]]/g, '\\$&').replace(/^-/, '\\-'))
|
|
28
|
+
.join(''));
|
|
29
|
+
};
|
|
30
|
+
// takes a glob string at a posix brace expression, and returns
|
|
31
|
+
// an equivalent regular expression source, and boolean indicating
|
|
32
|
+
// whether the /u flag needs to be applied, and the number of chars
|
|
33
|
+
// consumed to parse the character class.
|
|
34
|
+
// This also removes out of order ranges, and returns ($.) if the
|
|
35
|
+
// entire class just no good.
|
|
36
|
+
const parseClass = (glob, position) => {
|
|
37
|
+
const pos = position;
|
|
38
|
+
/* c8 ignore start */
|
|
39
|
+
if (glob.charAt(pos) !== '[') {
|
|
40
|
+
throw new Error('not in a brace expression');
|
|
41
|
+
}
|
|
42
|
+
/* c8 ignore stop */
|
|
43
|
+
const ranges = [];
|
|
44
|
+
const negs = [];
|
|
45
|
+
let i = pos + 1;
|
|
46
|
+
let sawStart = false;
|
|
47
|
+
let uflag = false;
|
|
48
|
+
let escaping = false;
|
|
49
|
+
let negate = false;
|
|
50
|
+
let endPos = pos;
|
|
51
|
+
let rangeStart = '';
|
|
52
|
+
WHILE: while (i < glob.length) {
|
|
53
|
+
const c = glob.charAt(i);
|
|
54
|
+
if ((c === '!' || c === '^') && i === pos + 1) {
|
|
55
|
+
negate = true;
|
|
56
|
+
i++;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (c === ']' && sawStart && !escaping) {
|
|
60
|
+
endPos = i + 1;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
sawStart = true;
|
|
64
|
+
if (c === '\\') {
|
|
65
|
+
if (!escaping) {
|
|
66
|
+
escaping = true;
|
|
67
|
+
i++;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// escaped \ char, fall through and treat like normal char
|
|
71
|
+
}
|
|
72
|
+
if (c === '[' && !escaping) {
|
|
73
|
+
// either a posix class, a collation equivalent, or just a [
|
|
74
|
+
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
75
|
+
if (glob.startsWith(cls, i)) {
|
|
76
|
+
// invalid, [a-[] is fine, but not [a-[:alpha]]
|
|
77
|
+
if (rangeStart) {
|
|
78
|
+
return ['$.', false, glob.length - pos];
|
|
79
|
+
}
|
|
80
|
+
i += cls.length;
|
|
81
|
+
if (neg)
|
|
82
|
+
negs.push(unip);
|
|
83
|
+
else
|
|
84
|
+
ranges.push(unip);
|
|
85
|
+
uflag = uflag || u;
|
|
86
|
+
continue WHILE;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// now it's just a normal character, effectively
|
|
91
|
+
escaping = false;
|
|
92
|
+
if (rangeStart) {
|
|
93
|
+
// throw this range away if it's not valid, but others
|
|
94
|
+
// can still match.
|
|
95
|
+
if (c > rangeStart) {
|
|
96
|
+
ranges.push(regExpEscape(rangeStart) + '-' + regExpEscape(c));
|
|
97
|
+
}
|
|
98
|
+
else if (c === rangeStart) {
|
|
99
|
+
ranges.push(regExpEscape(c));
|
|
100
|
+
}
|
|
101
|
+
rangeStart = '';
|
|
102
|
+
i++;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// now might be the start of a range.
|
|
106
|
+
// can be either c-d or c-] or c<more...>] or c] at this point
|
|
107
|
+
if (glob.startsWith('-]', i + 1)) {
|
|
108
|
+
ranges.push(regExpEscape(c + '-'));
|
|
109
|
+
i += 2;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (glob.startsWith('-', i + 1)) {
|
|
113
|
+
rangeStart = c;
|
|
114
|
+
i += 2;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// not the start of a range, just a single character
|
|
118
|
+
ranges.push(regExpEscape(c));
|
|
119
|
+
i++;
|
|
120
|
+
}
|
|
121
|
+
if (endPos < i) {
|
|
122
|
+
// didn't see the end of the class, not a valid class,
|
|
123
|
+
// but might still be valid as a literal match.
|
|
124
|
+
return ['', false, 0];
|
|
125
|
+
}
|
|
126
|
+
// if we got no ranges and no negates, then we have a range that
|
|
127
|
+
// cannot possibly match anything, and that poisons the whole glob
|
|
128
|
+
if (!ranges.length && !negs.length) {
|
|
129
|
+
return ['$.', false, glob.length - pos];
|
|
130
|
+
}
|
|
131
|
+
const sranges = '[' + (negate ? '^' : '') + rangesToString(ranges) + ']';
|
|
132
|
+
const snegs = '[' + (negate ? '' : '^') + rangesToString(negs) + ']';
|
|
133
|
+
const comb = ranges.length && negs.length
|
|
134
|
+
? '(' + sranges + '|' + snegs + ')'
|
|
135
|
+
: ranges.length
|
|
136
|
+
? sranges
|
|
137
|
+
: snegs;
|
|
138
|
+
return [comb, uflag, endPos - pos];
|
|
139
|
+
};
|
|
140
|
+
exports.parseClass = parseClass;
|
|
141
|
+
//# sourceMappingURL=brace-expressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brace-expressions.js","sourceRoot":"","sources":["../../src/brace-expressions.ts"],"names":[],"mappings":";AAAA,wEAAwE;AACxE,wCAAwC;;;AAExC,8DAA8D;AAC9D,MAAM,YAAY,GAA0D;IAC1E,WAAW,EAAE,CAAC,sBAAsB,EAAE,IAAI,CAAC;IAC3C,WAAW,EAAE,CAAC,eAAe,EAAE,IAAI,CAAC;IACpC,WAAW,EAAE,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,EAAE,KAAK,CAAC;IAC7C,WAAW,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC;IACjC,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;IAC9B,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;IAC9B,WAAW,EAAE,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC;IACzC,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;IAC9B,WAAW,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;IAC7B,WAAW,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;IAC7B,WAAW,EAAE,CAAC,uBAAuB,EAAE,IAAI,CAAC;IAC5C,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;IAC9B,UAAU,EAAE,CAAC,6BAA6B,EAAE,IAAI,CAAC;IACjD,YAAY,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC;CACnC,CAAA;AAED,+DAA+D;AAC/D,MAAM,YAAY,GAAG,CAA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AI,CAAC,GAAG,GAAG,CAAA;IACpE,MAAM,IAAI,GACR,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM;QAC1B,CAAC,CAAC,GAAG,GAAG,OAAO,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG;QACnC,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,KAAK,CAAA;IAEX,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,CAAA;AACpC,CAAC,CAAA;AAlHY,QAAA,UAAU,cAkHtB"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -37,7 +37,6 @@ export declare const GLOBSTAR: unique symbol;
|
|
|
37
37
|
export declare const filter: (pattern: string, options?: MinimatchOptions) => (p: string) => boolean;
|
|
38
38
|
export declare const defaults: (def: MinimatchOptions) => typeof minimatch;
|
|
39
39
|
export declare const braceExpand: (pattern: string, options?: MinimatchOptions) => string[];
|
|
40
|
-
declare const SUBPARSE: unique symbol;
|
|
41
40
|
export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
|
|
42
41
|
export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
|
|
43
42
|
export type MMRegExp = RegExp & {
|
|
@@ -78,7 +77,7 @@ export declare class Minimatch {
|
|
|
78
77
|
parseNegate(): void;
|
|
79
78
|
matchOne(file: string[], pattern: ParseReturn[], partial?: boolean): boolean;
|
|
80
79
|
braceExpand(): string[];
|
|
81
|
-
parse(pattern: string
|
|
80
|
+
parse(pattern: string): ParseReturn | SubparseReturn;
|
|
82
81
|
makeRe(): false | MMRegExp;
|
|
83
82
|
slashSplit(p: string): string[];
|
|
84
83
|
match(f: string, partial?: boolean): boolean;
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Minimatch = exports.match = exports.makeRe = exports.braceExpand = exports.defaults = exports.filter = exports.GLOBSTAR = exports.sep = exports.minimatch = void 0;
|
|
7
|
+
const brace_expansion_1 = __importDefault(require("brace-expansion"));
|
|
8
|
+
const brace_expressions_js_1 = require("./brace-expressions.js");
|
|
7
9
|
const minimatch = (p, pattern, options = {}) => {
|
|
8
10
|
assertValidPattern(pattern);
|
|
9
11
|
// shortcut: comments match nothing.
|
|
@@ -81,7 +83,6 @@ exports.sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep;
|
|
|
81
83
|
exports.minimatch.sep = exports.sep;
|
|
82
84
|
exports.GLOBSTAR = Symbol('globstar **');
|
|
83
85
|
exports.minimatch.GLOBSTAR = exports.GLOBSTAR;
|
|
84
|
-
const brace_expansion_1 = __importDefault(require("brace-expansion"));
|
|
85
86
|
const plTypes = {
|
|
86
87
|
'!': { open: '(?:(?!(?:', close: '))[^/]*?)' },
|
|
87
88
|
'?': { open: '(?:', close: ')?' },
|
|
@@ -182,7 +183,6 @@ const assertValidPattern = (pattern) => {
|
|
|
182
183
|
// when it is the *only* thing in a path portion. Otherwise, any series
|
|
183
184
|
// of * is equivalent to a single *. Globstar behavior is enabled by
|
|
184
185
|
// default, and can be disabled by setting options.noglobstar.
|
|
185
|
-
const SUBPARSE = Symbol('subparse');
|
|
186
186
|
const makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
|
|
187
187
|
exports.makeRe = makeRe;
|
|
188
188
|
exports.minimatch.makeRe = exports.makeRe;
|
|
@@ -199,9 +199,7 @@ exports.minimatch.match = exports.match;
|
|
|
199
199
|
// replace stuff like \* with *
|
|
200
200
|
const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
|
|
201
201
|
const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
202
|
-
const charUnescape = (s) => s.replace(/\\([^-\]])/g, '$1');
|
|
203
202
|
const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
204
|
-
const braExpEscape = (s) => s.replace(/[[\]\\]/g, '\\$&');
|
|
205
203
|
class Minimatch {
|
|
206
204
|
options;
|
|
207
205
|
set;
|
|
@@ -799,7 +797,7 @@ class Minimatch {
|
|
|
799
797
|
braceExpand() {
|
|
800
798
|
return (0, exports.braceExpand)(this.pattern, this.options);
|
|
801
799
|
}
|
|
802
|
-
parse(pattern
|
|
800
|
+
parse(pattern) {
|
|
803
801
|
assertValidPattern(pattern);
|
|
804
802
|
const options = this.options;
|
|
805
803
|
// shortcuts
|
|
@@ -811,34 +809,32 @@ class Minimatch {
|
|
|
811
809
|
// *, *.*, and *.<ext> Add a fast check method for those.
|
|
812
810
|
let m;
|
|
813
811
|
let fastTest = null;
|
|
814
|
-
if (
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
?
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
?
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
fastTest = dotStarTest;
|
|
841
|
-
}
|
|
812
|
+
if ((m = pattern.match(starRE))) {
|
|
813
|
+
fastTest = options.dot ? starTestDot : starTest;
|
|
814
|
+
}
|
|
815
|
+
else if ((m = pattern.match(starDotExtRE))) {
|
|
816
|
+
fastTest = (options.nocase
|
|
817
|
+
? options.dot
|
|
818
|
+
? starDotExtTestNocaseDot
|
|
819
|
+
: starDotExtTestNocase
|
|
820
|
+
: options.dot
|
|
821
|
+
? starDotExtTestDot
|
|
822
|
+
: starDotExtTest)(m[1]);
|
|
823
|
+
}
|
|
824
|
+
else if ((m = pattern.match(qmarksRE))) {
|
|
825
|
+
fastTest = (options.nocase
|
|
826
|
+
? options.dot
|
|
827
|
+
? qmarksTestNocaseDot
|
|
828
|
+
: qmarksTestNocase
|
|
829
|
+
: options.dot
|
|
830
|
+
? qmarksTestDot
|
|
831
|
+
: qmarksTest)(m);
|
|
832
|
+
}
|
|
833
|
+
else if ((m = pattern.match(starDotStarRE))) {
|
|
834
|
+
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
835
|
+
}
|
|
836
|
+
else if ((m = pattern.match(dotStarRE))) {
|
|
837
|
+
fastTest = dotStarTest;
|
|
842
838
|
}
|
|
843
839
|
let re = '';
|
|
844
840
|
let hasMagic = false;
|
|
@@ -847,12 +843,8 @@ class Minimatch {
|
|
|
847
843
|
const patternListStack = [];
|
|
848
844
|
const negativeLists = [];
|
|
849
845
|
let stateChar = false;
|
|
850
|
-
let
|
|
851
|
-
let reClassStart = -1;
|
|
852
|
-
let classStart = -1;
|
|
853
|
-
let cs;
|
|
846
|
+
let uflag = false;
|
|
854
847
|
let pl;
|
|
855
|
-
let sp;
|
|
856
848
|
// . and .. never match anything that doesn't start with .,
|
|
857
849
|
// even when options.dot is set. However, if the pattern
|
|
858
850
|
// starts with ., then traversal patterns can match.
|
|
@@ -915,10 +907,6 @@ class Minimatch {
|
|
|
915
907
|
}
|
|
916
908
|
/* c8 ignore stop */
|
|
917
909
|
case '\\':
|
|
918
|
-
if (inClass && pattern.charAt(i + 1) === '-') {
|
|
919
|
-
re += c;
|
|
920
|
-
continue;
|
|
921
|
-
}
|
|
922
910
|
clearStateChar();
|
|
923
911
|
escaping = true;
|
|
924
912
|
continue;
|
|
@@ -930,15 +918,6 @@ class Minimatch {
|
|
|
930
918
|
case '@':
|
|
931
919
|
case '!':
|
|
932
920
|
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
|
|
933
|
-
// all of those are literals inside a class, except that
|
|
934
|
-
// the glob [!a] means [^a] in regexp
|
|
935
|
-
if (inClass) {
|
|
936
|
-
this.debug(' in class');
|
|
937
|
-
if (c === '!' && i === classStart + 1)
|
|
938
|
-
c = '^';
|
|
939
|
-
re += c;
|
|
940
|
-
continue;
|
|
941
|
-
}
|
|
942
921
|
// if we already have a stateChar, then it means
|
|
943
922
|
// that there was something like ** or +? in there.
|
|
944
923
|
// Handle the stateChar, then proceed with this one.
|
|
@@ -952,10 +931,6 @@ class Minimatch {
|
|
|
952
931
|
clearStateChar();
|
|
953
932
|
continue;
|
|
954
933
|
case '(': {
|
|
955
|
-
if (inClass) {
|
|
956
|
-
re += '(';
|
|
957
|
-
continue;
|
|
958
|
-
}
|
|
959
934
|
if (!stateChar) {
|
|
960
935
|
re += '\\(';
|
|
961
936
|
continue;
|
|
@@ -982,7 +957,7 @@ class Minimatch {
|
|
|
982
957
|
}
|
|
983
958
|
case ')': {
|
|
984
959
|
const plEntry = patternListStack[patternListStack.length - 1];
|
|
985
|
-
if (
|
|
960
|
+
if (!plEntry) {
|
|
986
961
|
re += '\\)';
|
|
987
962
|
continue;
|
|
988
963
|
}
|
|
@@ -1001,7 +976,7 @@ class Minimatch {
|
|
|
1001
976
|
}
|
|
1002
977
|
case '|': {
|
|
1003
978
|
const plEntry = patternListStack[patternListStack.length - 1];
|
|
1004
|
-
if (
|
|
979
|
+
if (!plEntry) {
|
|
1005
980
|
re += '\\|';
|
|
1006
981
|
continue;
|
|
1007
982
|
}
|
|
@@ -1018,67 +993,27 @@ class Minimatch {
|
|
|
1018
993
|
case '[':
|
|
1019
994
|
// swallow any state-tracking char before the [
|
|
1020
995
|
clearStateChar();
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
996
|
+
const [src, needUflag, consumed] = (0, brace_expressions_js_1.parseClass)(pattern, i);
|
|
997
|
+
if (consumed) {
|
|
998
|
+
re += src;
|
|
999
|
+
uflag = uflag || needUflag;
|
|
1000
|
+
i += consumed - 1;
|
|
1001
|
+
hasMagic = true;
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
re += '\\[';
|
|
1024
1005
|
}
|
|
1025
|
-
inClass = true;
|
|
1026
|
-
classStart = i;
|
|
1027
|
-
reClassStart = re.length;
|
|
1028
|
-
re += c;
|
|
1029
1006
|
continue;
|
|
1030
1007
|
case ']':
|
|
1031
|
-
|
|
1032
|
-
// meaning and represent itself in
|
|
1033
|
-
// a bracket expression if it occurs
|
|
1034
|
-
// first in the list. -- POSIX.2 2.8.3.2
|
|
1035
|
-
if (i === classStart + 1 || !inClass) {
|
|
1036
|
-
re += '\\' + c;
|
|
1037
|
-
continue;
|
|
1038
|
-
}
|
|
1039
|
-
// split where the last [ was, make sure we don't have
|
|
1040
|
-
// an invalid re. if so, re-walk the contents of the
|
|
1041
|
-
// would-be class to re-translate any characters that
|
|
1042
|
-
// were passed through as-is
|
|
1043
|
-
// TODO: It would probably be faster to determine this
|
|
1044
|
-
// without a try/catch and a new RegExp, but it's tricky
|
|
1045
|
-
// to do safely. For now, this is safe and works.
|
|
1046
|
-
cs = pattern.substring(classStart + 1, i);
|
|
1047
|
-
try {
|
|
1048
|
-
RegExp('[' + braExpEscape(charUnescape(cs)) + ']');
|
|
1049
|
-
// looks good, finish up the class.
|
|
1050
|
-
re += c;
|
|
1051
|
-
}
|
|
1052
|
-
catch (er) {
|
|
1053
|
-
// out of order ranges in JS are errors, but in glob syntax,
|
|
1054
|
-
// they're just a range that matches nothing.
|
|
1055
|
-
re = re.substring(0, reClassStart) + '(?:$.)'; // match nothing ever
|
|
1056
|
-
}
|
|
1057
|
-
hasMagic = true;
|
|
1058
|
-
inClass = false;
|
|
1008
|
+
re += '\\' + c;
|
|
1059
1009
|
continue;
|
|
1060
1010
|
default:
|
|
1061
1011
|
// swallow any state char that wasn't consumed
|
|
1062
1012
|
clearStateChar();
|
|
1063
|
-
|
|
1064
|
-
re += '\\';
|
|
1065
|
-
}
|
|
1066
|
-
re += c;
|
|
1013
|
+
re += regExpEscape(c);
|
|
1067
1014
|
break;
|
|
1068
1015
|
} // switch
|
|
1069
1016
|
} // for
|
|
1070
|
-
// handle the case where we left a class open.
|
|
1071
|
-
// "[abc" is valid, equivalent to "\[abc"
|
|
1072
|
-
if (inClass) {
|
|
1073
|
-
// split where the last [ was, and escape it
|
|
1074
|
-
// this is a huge pita. We now have to re-walk
|
|
1075
|
-
// the contents of the would-be class to re-translate
|
|
1076
|
-
// any characters that were passed through as-is
|
|
1077
|
-
cs = pattern.slice(classStart + 1);
|
|
1078
|
-
sp = this.parse(cs, SUBPARSE);
|
|
1079
|
-
re = re.substring(0, reClassStart) + '\\[' + sp[0];
|
|
1080
|
-
hasMagic = hasMagic || sp[1];
|
|
1081
|
-
}
|
|
1082
1017
|
// handle the case where we had a +( thing at the *end*
|
|
1083
1018
|
// of the pattern.
|
|
1084
1019
|
// each pattern list stack adds 3 chars, and we need to go through
|
|
@@ -1141,7 +1076,7 @@ class Minimatch {
|
|
|
1141
1076
|
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
|
|
1142
1077
|
}
|
|
1143
1078
|
nlAfter = cleanAfter;
|
|
1144
|
-
const dollar = nlAfter === ''
|
|
1079
|
+
const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
|
|
1145
1080
|
re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
|
|
1146
1081
|
}
|
|
1147
1082
|
// if the re is not "" at this point, then we need to make sure
|
|
@@ -1153,10 +1088,6 @@ class Minimatch {
|
|
|
1153
1088
|
if (addPatternStart) {
|
|
1154
1089
|
re = patternStart() + re;
|
|
1155
1090
|
}
|
|
1156
|
-
// parsing just a piece of a larger pattern.
|
|
1157
|
-
if (isSub === SUBPARSE) {
|
|
1158
|
-
return [re, hasMagic];
|
|
1159
|
-
}
|
|
1160
1091
|
// if it's nocase, and the lcase/uppercase don't match, it's magic
|
|
1161
1092
|
if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
|
|
1162
1093
|
hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
|
|
@@ -1167,7 +1098,7 @@ class Minimatch {
|
|
|
1167
1098
|
if (!hasMagic) {
|
|
1168
1099
|
return globUnescape(pattern);
|
|
1169
1100
|
}
|
|
1170
|
-
const flags = options.nocase ? 'i' : '';
|
|
1101
|
+
const flags = (options.nocase ? 'i' : '') + (uflag ? 'u' : '');
|
|
1171
1102
|
try {
|
|
1172
1103
|
const ext = fastTest
|
|
1173
1104
|
? {
|