minimatch 7.1.4 → 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 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
 
@@ -254,6 +263,16 @@ paths](#windows).
254
263
  For legacy reasons, this is also set if
255
264
  `options.allowWindowsEscape` is set to the exact value `false`.
256
265
 
266
+ ### windowsNoMagicRoot
267
+
268
+ When a pattern starts with a UNC path or drive letter, and in
269
+ `nocase:true` mode, do not convert the root portions of the
270
+ pattern into a case-insensitive regular expression, and instead
271
+ leave them as strings.
272
+
273
+ This is the default when the platform is `win32` and
274
+ `nocase:true` is set.
275
+
257
276
  ### preserveMultipleSlashes
258
277
 
259
278
  By default, multiple `/` characters (other than the leading `//`
@@ -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,YAA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Ac,CAAC,IAAI,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"}
@@ -17,6 +17,7 @@ export interface MinimatchOptions {
17
17
  preserveMultipleSlashes?: boolean;
18
18
  optimizationLevel?: number;
19
19
  platform?: typeof process.platform;
20
+ windowsNoMagicRoot?: boolean;
20
21
  }
21
22
  export declare const minimatch: {
22
23
  (p: string, pattern: string, options?: MinimatchOptions): boolean;
@@ -36,7 +37,6 @@ export declare const GLOBSTAR: unique symbol;
36
37
  export declare const filter: (pattern: string, options?: MinimatchOptions) => (p: string) => boolean;
37
38
  export declare const defaults: (def: MinimatchOptions) => typeof minimatch;
38
39
  export declare const braceExpand: (pattern: string, options?: MinimatchOptions) => string[];
39
- declare const SUBPARSE: unique symbol;
40
40
  export declare const makeRe: (pattern: string, options?: MinimatchOptions) => false | MMRegExp;
41
41
  export declare const match: (list: string[], pattern: string, options?: MinimatchOptions) => string[];
42
42
  export type MMRegExp = RegExp & {
@@ -59,8 +59,10 @@ export declare class Minimatch {
59
59
  partial: boolean;
60
60
  globSet: string[];
61
61
  globParts: string[][];
62
+ nocase: boolean;
62
63
  isWindows: boolean;
63
64
  platform: typeof process.platform;
65
+ windowsNoMagicRoot: boolean;
64
66
  regexp: false | null | MMRegExp;
65
67
  constructor(pattern: string, options?: MinimatchOptions);
66
68
  debug(..._: any[]): void;
@@ -75,7 +77,7 @@ export declare class Minimatch {
75
77
  parseNegate(): void;
76
78
  matchOne(file: string[], pattern: ParseReturn[], partial?: boolean): boolean;
77
79
  braceExpand(): string[];
78
- parse(pattern: string, isSub?: typeof SUBPARSE): ParseReturn | SubparseReturn;
80
+ parse(pattern: string): ParseReturn | SubparseReturn;
79
81
  makeRe(): false | MMRegExp;
80
82
  slashSplit(p: string): string[];
81
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;
@@ -198,9 +198,8 @@ exports.match = match;
198
198
  exports.minimatch.match = exports.match;
199
199
  // replace stuff like \* with *
200
200
  const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
201
- const charUnescape = (s) => s.replace(/\\([^-\]])/g, '$1');
201
+ const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
202
202
  const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
203
- const braExpEscape = (s) => s.replace(/[[\]\\]/g, '\\$&');
204
203
  class Minimatch {
205
204
  options;
206
205
  set;
@@ -214,8 +213,10 @@ class Minimatch {
214
213
  partial;
215
214
  globSet;
216
215
  globParts;
216
+ nocase;
217
217
  isWindows;
218
218
  platform;
219
+ windowsNoMagicRoot;
219
220
  regexp;
220
221
  constructor(pattern, options = {}) {
221
222
  assertValidPattern(pattern);
@@ -236,6 +237,11 @@ class Minimatch {
236
237
  this.comment = false;
237
238
  this.empty = false;
238
239
  this.partial = !!options.partial;
240
+ this.nocase = !!this.options.nocase;
241
+ this.windowsNoMagicRoot =
242
+ options.windowsNoMagicRoot !== undefined
243
+ ? options.windowsNoMagicRoot
244
+ : !!(this.isWindows && this.nocase);
239
245
  this.globSet = [];
240
246
  this.globParts = [];
241
247
  this.set = [];
@@ -276,7 +282,23 @@ class Minimatch {
276
282
  this.globParts = this.preprocess(rawGlobParts);
277
283
  this.debug(this.pattern, this.globParts);
278
284
  // glob --> regexps
279
- let set = this.globParts.map((s, _, __) => s.map(ss => this.parse(ss)));
285
+ let set = this.globParts.map((s, _, __) => {
286
+ if (this.isWindows && this.windowsNoMagicRoot) {
287
+ // check if it's a drive or unc path.
288
+ const isUNC = s[0] === '' &&
289
+ s[1] === '' &&
290
+ (s[2] === '?' || !globMagic.test(s[2])) &&
291
+ !globMagic.test(s[3]);
292
+ const isDrive = /^[a-z]:/i.test(s[0]);
293
+ if (isUNC) {
294
+ return [...s.slice(0, 4), ...s.slice(4).map(ss => this.parse(ss))];
295
+ }
296
+ else if (isDrive) {
297
+ return [s[0], ...s.slice(1).map(ss => this.parse(ss))];
298
+ }
299
+ }
300
+ return s.map(ss => this.parse(ss));
301
+ });
280
302
  this.debug(this.pattern, set);
281
303
  // filter out everything that didn't compile properly.
282
304
  this.set = set.filter(s => s.indexOf(false) === -1);
@@ -775,7 +797,7 @@ class Minimatch {
775
797
  braceExpand() {
776
798
  return (0, exports.braceExpand)(this.pattern, this.options);
777
799
  }
778
- parse(pattern, isSub) {
800
+ parse(pattern) {
779
801
  assertValidPattern(pattern);
780
802
  const options = this.options;
781
803
  // shortcuts
@@ -787,34 +809,32 @@ class Minimatch {
787
809
  // *, *.*, and *.<ext> Add a fast check method for those.
788
810
  let m;
789
811
  let fastTest = null;
790
- if (isSub !== SUBPARSE) {
791
- if ((m = pattern.match(starRE))) {
792
- fastTest = options.dot ? starTestDot : starTest;
793
- }
794
- else if ((m = pattern.match(starDotExtRE))) {
795
- fastTest = (options.nocase
796
- ? options.dot
797
- ? starDotExtTestNocaseDot
798
- : starDotExtTestNocase
799
- : options.dot
800
- ? starDotExtTestDot
801
- : starDotExtTest)(m[1]);
802
- }
803
- else if ((m = pattern.match(qmarksRE))) {
804
- fastTest = (options.nocase
805
- ? options.dot
806
- ? qmarksTestNocaseDot
807
- : qmarksTestNocase
808
- : options.dot
809
- ? qmarksTestDot
810
- : qmarksTest)(m);
811
- }
812
- else if ((m = pattern.match(starDotStarRE))) {
813
- fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
814
- }
815
- else if ((m = pattern.match(dotStarRE))) {
816
- fastTest = dotStarTest;
817
- }
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;
818
838
  }
819
839
  let re = '';
820
840
  let hasMagic = false;
@@ -823,12 +843,8 @@ class Minimatch {
823
843
  const patternListStack = [];
824
844
  const negativeLists = [];
825
845
  let stateChar = false;
826
- let inClass = false;
827
- let reClassStart = -1;
828
- let classStart = -1;
829
- let cs;
846
+ let uflag = false;
830
847
  let pl;
831
- let sp;
832
848
  // . and .. never match anything that doesn't start with .,
833
849
  // even when options.dot is set. However, if the pattern
834
850
  // starts with ., then traversal patterns can match.
@@ -891,10 +907,6 @@ class Minimatch {
891
907
  }
892
908
  /* c8 ignore stop */
893
909
  case '\\':
894
- if (inClass && pattern.charAt(i + 1) === '-') {
895
- re += c;
896
- continue;
897
- }
898
910
  clearStateChar();
899
911
  escaping = true;
900
912
  continue;
@@ -906,15 +918,6 @@ class Minimatch {
906
918
  case '@':
907
919
  case '!':
908
920
  this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
909
- // all of those are literals inside a class, except that
910
- // the glob [!a] means [^a] in regexp
911
- if (inClass) {
912
- this.debug(' in class');
913
- if (c === '!' && i === classStart + 1)
914
- c = '^';
915
- re += c;
916
- continue;
917
- }
918
921
  // if we already have a stateChar, then it means
919
922
  // that there was something like ** or +? in there.
920
923
  // Handle the stateChar, then proceed with this one.
@@ -928,10 +931,6 @@ class Minimatch {
928
931
  clearStateChar();
929
932
  continue;
930
933
  case '(': {
931
- if (inClass) {
932
- re += '(';
933
- continue;
934
- }
935
934
  if (!stateChar) {
936
935
  re += '\\(';
937
936
  continue;
@@ -958,7 +957,7 @@ class Minimatch {
958
957
  }
959
958
  case ')': {
960
959
  const plEntry = patternListStack[patternListStack.length - 1];
961
- if (inClass || !plEntry) {
960
+ if (!plEntry) {
962
961
  re += '\\)';
963
962
  continue;
964
963
  }
@@ -977,7 +976,7 @@ class Minimatch {
977
976
  }
978
977
  case '|': {
979
978
  const plEntry = patternListStack[patternListStack.length - 1];
980
- if (inClass || !plEntry) {
979
+ if (!plEntry) {
981
980
  re += '\\|';
982
981
  continue;
983
982
  }
@@ -994,67 +993,27 @@ class Minimatch {
994
993
  case '[':
995
994
  // swallow any state-tracking char before the [
996
995
  clearStateChar();
997
- if (inClass) {
998
- re += '\\' + c;
999
- continue;
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 += '\\[';
1000
1005
  }
1001
- inClass = true;
1002
- classStart = i;
1003
- reClassStart = re.length;
1004
- re += c;
1005
1006
  continue;
1006
1007
  case ']':
1007
- // a right bracket shall lose its special
1008
- // meaning and represent itself in
1009
- // a bracket expression if it occurs
1010
- // first in the list. -- POSIX.2 2.8.3.2
1011
- if (i === classStart + 1 || !inClass) {
1012
- re += '\\' + c;
1013
- continue;
1014
- }
1015
- // split where the last [ was, make sure we don't have
1016
- // an invalid re. if so, re-walk the contents of the
1017
- // would-be class to re-translate any characters that
1018
- // were passed through as-is
1019
- // TODO: It would probably be faster to determine this
1020
- // without a try/catch and a new RegExp, but it's tricky
1021
- // to do safely. For now, this is safe and works.
1022
- cs = pattern.substring(classStart + 1, i);
1023
- try {
1024
- RegExp('[' + braExpEscape(charUnescape(cs)) + ']');
1025
- // looks good, finish up the class.
1026
- re += c;
1027
- }
1028
- catch (er) {
1029
- // out of order ranges in JS are errors, but in glob syntax,
1030
- // they're just a range that matches nothing.
1031
- re = re.substring(0, reClassStart) + '(?:$.)'; // match nothing ever
1032
- }
1033
- hasMagic = true;
1034
- inClass = false;
1008
+ re += '\\' + c;
1035
1009
  continue;
1036
1010
  default:
1037
1011
  // swallow any state char that wasn't consumed
1038
1012
  clearStateChar();
1039
- if (reSpecials[c] && !(c === '^' && inClass)) {
1040
- re += '\\';
1041
- }
1042
- re += c;
1013
+ re += regExpEscape(c);
1043
1014
  break;
1044
1015
  } // switch
1045
1016
  } // for
1046
- // handle the case where we left a class open.
1047
- // "[abc" is valid, equivalent to "\[abc"
1048
- if (inClass) {
1049
- // split where the last [ was, and escape it
1050
- // this is a huge pita. We now have to re-walk
1051
- // the contents of the would-be class to re-translate
1052
- // any characters that were passed through as-is
1053
- cs = pattern.slice(classStart + 1);
1054
- sp = this.parse(cs, SUBPARSE);
1055
- re = re.substring(0, reClassStart) + '\\[' + sp[0];
1056
- hasMagic = hasMagic || sp[1];
1057
- }
1058
1017
  // handle the case where we had a +( thing at the *end*
1059
1018
  // of the pattern.
1060
1019
  // each pattern list stack adds 3 chars, and we need to go through
@@ -1117,7 +1076,7 @@ class Minimatch {
1117
1076
  cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
1118
1077
  }
1119
1078
  nlAfter = cleanAfter;
1120
- const dollar = nlAfter === '' && isSub !== SUBPARSE ? '(?:$|\\/)' : '';
1079
+ const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
1121
1080
  re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
1122
1081
  }
1123
1082
  // if the re is not "" at this point, then we need to make sure
@@ -1129,10 +1088,6 @@ class Minimatch {
1129
1088
  if (addPatternStart) {
1130
1089
  re = patternStart() + re;
1131
1090
  }
1132
- // parsing just a piece of a larger pattern.
1133
- if (isSub === SUBPARSE) {
1134
- return [re, hasMagic];
1135
- }
1136
1091
  // if it's nocase, and the lcase/uppercase don't match, it's magic
1137
1092
  if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
1138
1093
  hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
@@ -1143,7 +1098,7 @@ class Minimatch {
1143
1098
  if (!hasMagic) {
1144
1099
  return globUnescape(pattern);
1145
1100
  }
1146
- const flags = options.nocase ? 'i' : '';
1101
+ const flags = (options.nocase ? 'i' : '') + (uflag ? 'u' : '');
1147
1102
  try {
1148
1103
  const ext = fastTest
1149
1104
  ? {