pnpm 10.34.3 → 10.34.5

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.
Files changed (59) hide show
  1. package/dist/node_modules/.modules.yaml +57 -57
  2. package/dist/node_modules/.pnpm/lock.yaml +27 -27
  3. package/dist/node_modules/.pnpm-workspace-state-v1.json +3 -3
  4. package/dist/node_modules/brace-expansion/.tap/processinfo/8b906b8c-e21f-40b5-8c0d-214d8c2682c5.json +719 -0
  5. package/dist/node_modules/brace-expansion/dist/commonjs/index.d.ts.map +1 -0
  6. package/dist/node_modules/brace-expansion/dist/commonjs/index.js +263 -0
  7. package/dist/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -0
  8. package/dist/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
  9. package/dist/node_modules/brace-expansion/dist/esm/index.d.ts.map +1 -0
  10. package/dist/node_modules/brace-expansion/dist/esm/index.js +259 -0
  11. package/dist/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
  12. package/dist/node_modules/brace-expansion/dist/esm/package.json +3 -0
  13. package/dist/node_modules/brace-expansion/index.js +29 -17
  14. package/dist/node_modules/brace-expansion/package.json +1 -1
  15. package/dist/node_modules/p-map/index.js +2 -1
  16. package/dist/node_modules/p-map/package.json +1 -1
  17. package/dist/node_modules/picomatch/lib/parse.js +39 -9
  18. package/dist/node_modules/picomatch/lib/picomatch.js +14 -2
  19. package/dist/node_modules/picomatch/package.json +3 -2
  20. package/dist/node_modules/semver/classes/range.js +6 -2
  21. package/dist/node_modules/semver/package.json +1 -1
  22. package/dist/node_modules/tar/dist/commonjs/header.d.ts.map +1 -1
  23. package/dist/node_modules/tar/dist/commonjs/header.js +5 -4
  24. package/dist/node_modules/tar/dist/commonjs/header.js.map +1 -1
  25. package/dist/node_modules/tar/dist/commonjs/index.min.js +3 -3
  26. package/dist/node_modules/tar/dist/commonjs/index.min.js.map +3 -3
  27. package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.d.ts.map +1 -1
  28. package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.js +2 -2
  29. package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.js.map +1 -1
  30. package/dist/node_modules/tar/dist/commonjs/options.d.ts.map +1 -1
  31. package/dist/node_modules/tar/dist/commonjs/options.js.map +1 -1
  32. package/dist/node_modules/tar/dist/commonjs/parse.d.ts.map +1 -1
  33. package/dist/node_modules/tar/dist/commonjs/parse.js +39 -4
  34. package/dist/node_modules/tar/dist/commonjs/parse.js.map +1 -1
  35. package/dist/node_modules/tar/dist/commonjs/pax.js +30 -6
  36. package/dist/node_modules/tar/dist/commonjs/pax.js.map +1 -1
  37. package/dist/node_modules/tar/dist/commonjs/unpack.js +2 -2
  38. package/dist/node_modules/tar/dist/commonjs/unpack.js.map +1 -1
  39. package/dist/node_modules/tar/dist/esm/header.d.ts.map +1 -1
  40. package/dist/node_modules/tar/dist/esm/header.js +5 -4
  41. package/dist/node_modules/tar/dist/esm/header.js.map +1 -1
  42. package/dist/node_modules/tar/dist/esm/index.min.js +3 -3
  43. package/dist/node_modules/tar/dist/esm/index.min.js.map +3 -3
  44. package/dist/node_modules/tar/dist/esm/normalize-windows-path.d.ts.map +1 -1
  45. package/dist/node_modules/tar/dist/esm/normalize-windows-path.js +2 -2
  46. package/dist/node_modules/tar/dist/esm/normalize-windows-path.js.map +1 -1
  47. package/dist/node_modules/tar/dist/esm/options.d.ts.map +1 -1
  48. package/dist/node_modules/tar/dist/esm/options.js.map +1 -1
  49. package/dist/node_modules/tar/dist/esm/parse.d.ts.map +1 -1
  50. package/dist/node_modules/tar/dist/esm/parse.js +39 -4
  51. package/dist/node_modules/tar/dist/esm/parse.js.map +1 -1
  52. package/dist/node_modules/tar/dist/esm/pax.js +30 -6
  53. package/dist/node_modules/tar/dist/esm/pax.js.map +1 -1
  54. package/dist/node_modules/tar/dist/esm/unpack.js +2 -2
  55. package/dist/node_modules/tar/dist/esm/unpack.js.map +1 -1
  56. package/dist/node_modules/tar/package.json +1 -1
  57. package/dist/pnpm.cjs +598 -345
  58. package/dist/worker.js +1303 -10
  59. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa,SAAU,CAAA;AAYpC,eAAO,MAAM,oBAAoB,UAAY,CAAA;AAwD7C,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,YAkBtE"}
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXPANSION_MAX_LENGTH = exports.EXPANSION_MAX = void 0;
4
+ exports.expand = expand;
5
+ const balanced_match_1 = require("balanced-match");
6
+ const escSlash = '\0SLASH' + Math.random() + '\0';
7
+ const escOpen = '\0OPEN' + Math.random() + '\0';
8
+ const escClose = '\0CLOSE' + Math.random() + '\0';
9
+ const escComma = '\0COMMA' + Math.random() + '\0';
10
+ const escPeriod = '\0PERIOD' + Math.random() + '\0';
11
+ const escSlashPattern = new RegExp(escSlash, 'g');
12
+ const escOpenPattern = new RegExp(escOpen, 'g');
13
+ const escClosePattern = new RegExp(escClose, 'g');
14
+ const escCommaPattern = new RegExp(escComma, 'g');
15
+ const escPeriodPattern = new RegExp(escPeriod, 'g');
16
+ const slashPattern = /\\\\/g;
17
+ const openPattern = /\\{/g;
18
+ const closePattern = /\\}/g;
19
+ const commaPattern = /\\,/g;
20
+ const periodPattern = /\\\./g;
21
+ exports.EXPANSION_MAX = 100_000;
22
+ // `EXPANSION_MAX` caps the *number* of expansions, but not their length. An
23
+ // input like `'{a,b}'.repeat(1500)` stays under that count - its output is
24
+ // truncated to 100k results - while making every result ~1500 characters
25
+ // long. The result set, and the intermediate arrays built while combining
26
+ // brace sets, then grow large enough to exhaust memory and crash the process
27
+ // (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of
28
+ // characters the accumulator may hold at any point, so memory stays flat no
29
+ // matter how many brace groups are chained. The limit sits well above any
30
+ // realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M
31
+ // characters) so legitimate input is unaffected.
32
+ exports.EXPANSION_MAX_LENGTH = 4_000_000;
33
+ function numeric(str) {
34
+ return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
35
+ }
36
+ function escapeBraces(str) {
37
+ return str
38
+ .replace(slashPattern, escSlash)
39
+ .replace(openPattern, escOpen)
40
+ .replace(closePattern, escClose)
41
+ .replace(commaPattern, escComma)
42
+ .replace(periodPattern, escPeriod);
43
+ }
44
+ function unescapeBraces(str) {
45
+ return str
46
+ .replace(escSlashPattern, '\\')
47
+ .replace(escOpenPattern, '{')
48
+ .replace(escClosePattern, '}')
49
+ .replace(escCommaPattern, ',')
50
+ .replace(escPeriodPattern, '.');
51
+ }
52
+ /**
53
+ * Basically just str.split(","), but handling cases
54
+ * where we have nested braced sections, which should be
55
+ * treated as individual members, like {a,{b,c},d}
56
+ */
57
+ function parseCommaParts(str) {
58
+ if (!str) {
59
+ return [''];
60
+ }
61
+ const parts = [];
62
+ const m = (0, balanced_match_1.balanced)('{', '}', str);
63
+ if (!m) {
64
+ return str.split(',');
65
+ }
66
+ const { pre, body, post } = m;
67
+ const p = pre.split(',');
68
+ p[p.length - 1] += '{' + body + '}';
69
+ const postParts = parseCommaParts(post);
70
+ if (post.length) {
71
+ ;
72
+ p[p.length - 1] += postParts.shift();
73
+ p.push.apply(p, postParts);
74
+ }
75
+ parts.push.apply(parts, p);
76
+ return parts;
77
+ }
78
+ function expand(str, options = {}) {
79
+ if (!str) {
80
+ return [];
81
+ }
82
+ const { max = exports.EXPANSION_MAX, maxLength = exports.EXPANSION_MAX_LENGTH } = options;
83
+ // I don't know why Bash 4.3 does this, but it does.
84
+ // Anything starting with {} will have the first two bytes preserved
85
+ // but *only* at the top level, so {},a}b will not expand to anything,
86
+ // but a{},b}c will be expanded to [a}c,abc].
87
+ // One could argue that this is a bug in Bash, but since the goal of
88
+ // this module is to match Bash's rules, we escape a leading {}
89
+ if (str.slice(0, 2) === '{}') {
90
+ str = '\\{\\}' + str.slice(2);
91
+ }
92
+ return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces);
93
+ }
94
+ function embrace(str) {
95
+ return '{' + str + '}';
96
+ }
97
+ function isPadded(el) {
98
+ return /^-?0\d/.test(el);
99
+ }
100
+ function lte(i, y) {
101
+ return i <= y;
102
+ }
103
+ function gte(i, y) {
104
+ return i >= y;
105
+ }
106
+ // Build `{ acc[a] + pre + values[v] }` for every combination, capping the
107
+ // number of results at `max` and the total number of characters at `maxLength`.
108
+ // This is the one place output grows, so bounding it here keeps the single
109
+ // accumulator - and therefore memory - flat regardless of how many brace groups
110
+ // are combined (CVE-2026-14257).
111
+ function combine(acc, pre, values, max, maxLength, dropEmpties) {
112
+ const out = [];
113
+ let length = 0;
114
+ for (let a = 0; a < acc.length; a++) {
115
+ for (let v = 0; v < values.length; v++) {
116
+ if (out.length >= max)
117
+ return out;
118
+ const expansion = acc[a] + pre + values[v];
119
+ // Bash drops empty results at the top level. Skip them before they count
120
+ // against `max`, so `max` bounds the number of *kept* results.
121
+ if (dropEmpties && !expansion)
122
+ continue;
123
+ if (length + expansion.length > maxLength)
124
+ return out;
125
+ out.push(expansion);
126
+ length += expansion.length;
127
+ }
128
+ }
129
+ return out;
130
+ }
131
+ // The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
132
+ // sequence body.
133
+ function expandSequence(body, isAlphaSequence, max) {
134
+ const n = body.split(/\.\./);
135
+ const N = [];
136
+ // A sequence body always splits into two or three parts, but the compiler
137
+ // can't know that.
138
+ /* c8 ignore start */
139
+ if (n[0] === undefined || n[1] === undefined) {
140
+ return N;
141
+ }
142
+ /* c8 ignore stop */
143
+ const x = numeric(n[0]);
144
+ const y = numeric(n[1]);
145
+ const width = Math.max(n[0].length, n[1].length);
146
+ let incr = n.length === 3 && n[2] !== undefined ?
147
+ Math.max(Math.abs(numeric(n[2])), 1)
148
+ : 1;
149
+ let test = lte;
150
+ const reverse = y < x;
151
+ if (reverse) {
152
+ incr *= -1;
153
+ test = gte;
154
+ }
155
+ const pad = n.some(isPadded);
156
+ for (let i = x; test(i, y) && N.length < max; i += incr) {
157
+ let c;
158
+ if (isAlphaSequence) {
159
+ c = String.fromCharCode(i);
160
+ if (c === '\\') {
161
+ c = '';
162
+ }
163
+ }
164
+ else {
165
+ c = String(i);
166
+ if (pad) {
167
+ const need = width - c.length;
168
+ if (need > 0) {
169
+ const z = new Array(need + 1).join('0');
170
+ if (i < 0) {
171
+ c = '-' + z + c.slice(1);
172
+ }
173
+ else {
174
+ c = z + c;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ N.push(c);
180
+ }
181
+ return N;
182
+ }
183
+ function expand_(str, max, maxLength, isTop) {
184
+ // Consume the string's top-level brace groups left to right, threading a
185
+ // running set of combined prefixes (`acc`). Expanding the tail iteratively -
186
+ // rather than recursing on `m.post` once per group - keeps the native stack
187
+ // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no
188
+ // longer overflow the stack, and leaves a single accumulator whose size
189
+ // `maxLength` bounds directly (CVE-2026-14257).
190
+ let acc = [''];
191
+ // Bash drops empty results, but only when the *first* top-level group is a
192
+ // comma set - a sequence like `{a..\}` may legitimately yield ''. The drop
193
+ // is on the final strings, so it is applied to whichever `combine` produces
194
+ // them (the one with no brace set left in the tail).
195
+ let dropEmpties = false;
196
+ let firstGroup = true;
197
+ for (;;) {
198
+ const m = (0, balanced_match_1.balanced)('{', '}', str);
199
+ // No brace set left: the rest of the string is literal.
200
+ if (!m) {
201
+ return combine(acc, str, [''], max, maxLength, dropEmpties);
202
+ }
203
+ // no need to expand pre, since it is guaranteed to be free of brace-sets
204
+ const pre = m.pre;
205
+ if (/\$$/.test(pre)) {
206
+ acc = combine(acc, pre + '{' + m.body + '}', [''], max, maxLength, dropEmpties && !m.post.length);
207
+ firstGroup = false;
208
+ if (!m.post.length)
209
+ break;
210
+ str = m.post;
211
+ continue;
212
+ }
213
+ const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
214
+ const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
215
+ const isSequence = isNumericSequence || isAlphaSequence;
216
+ const isOptions = m.body.indexOf(',') >= 0;
217
+ if (!isSequence && !isOptions) {
218
+ // {a},b}
219
+ if (m.post.match(/,(?!,).*\}/)) {
220
+ str = m.pre + '{' + m.body + escClose + m.post;
221
+ isTop = true;
222
+ continue;
223
+ }
224
+ // Nothing here expands, so the whole remaining string is literal.
225
+ return combine(acc, pre + '{' + m.body + '}' + m.post, [''], max, maxLength, dropEmpties);
226
+ }
227
+ if (firstGroup) {
228
+ dropEmpties = isTop && !isSequence;
229
+ firstGroup = false;
230
+ }
231
+ let values;
232
+ if (isSequence) {
233
+ values = expandSequence(m.body, isAlphaSequence, max);
234
+ }
235
+ else {
236
+ let n = parseCommaParts(m.body);
237
+ if (n.length === 1 && n[0] !== undefined) {
238
+ // x{{a,b}}y ==> x{a}y x{b}y
239
+ n = expand_(n[0], max, maxLength, false).map(embrace);
240
+ //XXX is this necessary? Can't seem to hit it in tests.
241
+ /* c8 ignore start */
242
+ if (n.length === 1) {
243
+ acc = combine(acc, pre + n[0], [''], max, maxLength, dropEmpties && !m.post.length);
244
+ if (!m.post.length)
245
+ break;
246
+ str = m.post;
247
+ continue;
248
+ }
249
+ /* c8 ignore stop */
250
+ }
251
+ values = [];
252
+ for (let j = 0; j < n.length; j++) {
253
+ values.push.apply(values, expand_(n[j], max, maxLength, false));
254
+ }
255
+ }
256
+ acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
257
+ if (!m.post.length)
258
+ break;
259
+ str = m.post;
260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,EACH,SAAS,EACT,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAC9B,CAAA;oBACD,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;wBAAE,MAAK;oBACzB,GAAG,GAAG,CAAC,CAAC,IAAI,CAAA;oBACZ,SAAQ;gBACV,CAAC;gBACD,oBAAoB;YACtB,CAAC;YAED,MAAM,GAAG,EAAE,CAAA;YACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;YAC3E,CAAC;QACH,CAAC;QAED,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC9E,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;YAAE,MAAK;QACzB,GAAG,GAAG,CAAC,CAAC,IAAI,CAAA;IACd,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { balanced } from 'balanced-match'\n\nconst escSlash = '\\0SLASH' + Math.random() + '\\0'\nconst escOpen = '\\0OPEN' + Math.random() + '\\0'\nconst escClose = '\\0CLOSE' + Math.random() + '\\0'\nconst escComma = '\\0COMMA' + Math.random() + '\\0'\nconst escPeriod = '\\0PERIOD' + Math.random() + '\\0'\nconst escSlashPattern = new RegExp(escSlash, 'g')\nconst escOpenPattern = new RegExp(escOpen, 'g')\nconst escClosePattern = new RegExp(escClose, 'g')\nconst escCommaPattern = new RegExp(escComma, 'g')\nconst escPeriodPattern = new RegExp(escPeriod, 'g')\nconst slashPattern = /\\\\\\\\/g\nconst openPattern = /\\\\{/g\nconst closePattern = /\\\\}/g\nconst commaPattern = /\\\\,/g\nconst periodPattern = /\\\\\\./g\n\nexport const EXPANSION_MAX = 100_000\n\n// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An\n// input like `'{a,b}'.repeat(1500)` stays under that count - its output is\n// truncated to 100k results - while making every result ~1500 characters\n// long. The result set, and the intermediate arrays built while combining\n// brace sets, then grow large enough to exhaust memory and crash the process\n// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of\n// characters the accumulator may hold at any point, so memory stays flat no\n// matter how many brace groups are chained. The limit sits well above any\n// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M\n// characters) so legitimate input is unaffected.\nexport const EXPANSION_MAX_LENGTH = 4_000_000\n\nfunction numeric(str: string) {\n return !isNaN(str as any) ? parseInt(str, 10) : str.charCodeAt(0)\n}\n\nfunction escapeBraces(str: string) {\n return str\n .replace(slashPattern, escSlash)\n .replace(openPattern, escOpen)\n .replace(closePattern, escClose)\n .replace(commaPattern, escComma)\n .replace(periodPattern, escPeriod)\n}\n\nfunction unescapeBraces(str: string) {\n return str\n .replace(escSlashPattern, '\\\\')\n .replace(escOpenPattern, '{')\n .replace(escClosePattern, '}')\n .replace(escCommaPattern, ',')\n .replace(escPeriodPattern, '.')\n}\n\n/**\n * Basically just str.split(\",\"), but handling cases\n * where we have nested braced sections, which should be\n * treated as individual members, like {a,{b,c},d}\n */\nfunction parseCommaParts(str: string) {\n if (!str) {\n return ['']\n }\n\n const parts: string[] = []\n const m = balanced('{', '}', str)\n\n if (!m) {\n return str.split(',')\n }\n\n const { pre, body, post } = m\n const p = pre.split(',')\n\n p[p.length - 1] += '{' + body + '}'\n const postParts = parseCommaParts(post)\n if (post.length) {\n ;(p[p.length - 1] as string) += postParts.shift()\n p.push.apply(p, postParts)\n }\n\n parts.push.apply(parts, p)\n\n return parts\n}\n\nexport type BraceExpansionOptions = {\n max?: number\n maxLength?: number\n}\n\nexport function expand(str: string, options: BraceExpansionOptions = {}) {\n if (!str) {\n return []\n }\n\n const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options\n\n // I don't know why Bash 4.3 does this, but it does.\n // Anything starting with {} will have the first two bytes preserved\n // but *only* at the top level, so {},a}b will not expand to anything,\n // but a{},b}c will be expanded to [a}c,abc].\n // One could argue that this is a bug in Bash, but since the goal of\n // this module is to match Bash's rules, we escape a leading {}\n if (str.slice(0, 2) === '{}') {\n str = '\\\\{\\\\}' + str.slice(2)\n }\n\n return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces)\n}\n\nfunction embrace(str: string) {\n return '{' + str + '}'\n}\n\nfunction isPadded(el: string) {\n return /^-?0\\d/.test(el)\n}\n\nfunction lte(i: number, y: number) {\n return i <= y\n}\n\nfunction gte(i: number, y: number) {\n return i >= y\n}\n\n// Build `{ acc[a] + pre + values[v] }` for every combination, capping the\n// number of results at `max` and the total number of characters at `maxLength`.\n// This is the one place output grows, so bounding it here keeps the single\n// accumulator - and therefore memory - flat regardless of how many brace groups\n// are combined (CVE-2026-14257).\nfunction combine(\n acc: string[],\n pre: string,\n values: string[],\n max: number,\n maxLength: number,\n dropEmpties: boolean,\n): string[] {\n const out: string[] = []\n let length = 0\n for (let a = 0; a < acc.length; a++) {\n for (let v = 0; v < values.length; v++) {\n if (out.length >= max) return out\n const expansion = (acc[a] as string) + pre + values[v]\n // Bash drops empty results at the top level. Skip them before they count\n // against `max`, so `max` bounds the number of *kept* results.\n if (dropEmpties && !expansion) continue\n if (length + expansion.length > maxLength) return out\n out.push(expansion)\n length += expansion.length\n }\n }\n return out\n}\n\n// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)\n// sequence body.\nfunction expandSequence(\n body: string,\n isAlphaSequence: boolean,\n max: number,\n): string[] {\n const n = body.split(/\\.\\./)\n const N: string[] = []\n // A sequence body always splits into two or three parts, but the compiler\n // can't know that.\n /* c8 ignore start */\n if (n[0] === undefined || n[1] === undefined) {\n return N\n }\n /* c8 ignore stop */\n const x = numeric(n[0])\n const y = numeric(n[1])\n const width = Math.max(n[0].length, n[1].length)\n let incr =\n n.length === 3 && n[2] !== undefined ?\n Math.max(Math.abs(numeric(n[2])), 1)\n : 1\n let test = lte\n const reverse = y < x\n if (reverse) {\n incr *= -1\n test = gte\n }\n const pad = n.some(isPadded)\n\n for (let i = x; test(i, y) && N.length < max; i += incr) {\n let c\n if (isAlphaSequence) {\n c = String.fromCharCode(i)\n if (c === '\\\\') {\n c = ''\n }\n } else {\n c = String(i)\n if (pad) {\n const need = width - c.length\n if (need > 0) {\n const z = new Array(need + 1).join('0')\n if (i < 0) {\n c = '-' + z + c.slice(1)\n } else {\n c = z + c\n }\n }\n }\n }\n N.push(c)\n }\n return N\n}\n\nfunction expand_(\n str: string,\n max: number,\n maxLength: number,\n isTop: boolean,\n): string[] {\n // Consume the string's top-level brace groups left to right, threading a\n // running set of combined prefixes (`acc`). Expanding the tail iteratively -\n // rather than recursing on `m.post` once per group - keeps the native stack\n // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no\n // longer overflow the stack, and leaves a single accumulator whose size\n // `maxLength` bounds directly (CVE-2026-14257).\n let acc: string[] = ['']\n\n // Bash drops empty results, but only when the *first* top-level group is a\n // comma set - a sequence like `{a..\\}` may legitimately yield ''. The drop\n // is on the final strings, so it is applied to whichever `combine` produces\n // them (the one with no brace set left in the tail).\n let dropEmpties = false\n let firstGroup = true\n\n for (;;) {\n const m = balanced('{', '}', str)\n\n // No brace set left: the rest of the string is literal.\n if (!m) {\n return combine(acc, str, [''], max, maxLength, dropEmpties)\n }\n\n // no need to expand pre, since it is guaranteed to be free of brace-sets\n const pre = m.pre\n\n if (/\\$$/.test(pre)) {\n acc = combine(\n acc,\n pre + '{' + m.body + '}',\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n firstGroup = false\n if (!m.post.length) break\n str = m.post\n continue\n }\n\n const isNumericSequence = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(m.body)\n const isAlphaSequence = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(\n m.body,\n )\n const isSequence = isNumericSequence || isAlphaSequence\n const isOptions = m.body.indexOf(',') >= 0\n if (!isSequence && !isOptions) {\n // {a},b}\n if (m.post.match(/,(?!,).*\\}/)) {\n str = m.pre + '{' + m.body + escClose + m.post\n isTop = true\n continue\n }\n // Nothing here expands, so the whole remaining string is literal.\n return combine(\n acc,\n pre + '{' + m.body + '}' + m.post,\n [''],\n max,\n maxLength,\n dropEmpties,\n )\n }\n\n if (firstGroup) {\n dropEmpties = isTop && !isSequence\n firstGroup = false\n }\n\n let values: string[]\n if (isSequence) {\n values = expandSequence(m.body, isAlphaSequence, max)\n } else {\n let n = parseCommaParts(m.body)\n if (n.length === 1 && n[0] !== undefined) {\n // x{{a,b}}y ==> x{a}y x{b}y\n n = expand_(n[0], max, maxLength, false).map(embrace)\n //XXX is this necessary? Can't seem to hit it in tests.\n /* c8 ignore start */\n if (n.length === 1) {\n acc = combine(\n acc,\n pre + n[0],\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n if (!m.post.length) break\n str = m.post\n continue\n }\n /* c8 ignore stop */\n }\n\n values = []\n for (let j = 0; j < n.length; j++) {\n values.push.apply(values, expand_(n[j] as string, max, maxLength, false))\n }\n }\n\n acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length)\n if (!m.post.length) break\n str = m.post\n }\n\n return acc\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa,SAAU,CAAA;AAYpC,eAAO,MAAM,oBAAoB,UAAY,CAAA;AAwD7C,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,YAkBtE"}
@@ -0,0 +1,259 @@
1
+ import { balanced } from 'balanced-match';
2
+ const escSlash = '\0SLASH' + Math.random() + '\0';
3
+ const escOpen = '\0OPEN' + Math.random() + '\0';
4
+ const escClose = '\0CLOSE' + Math.random() + '\0';
5
+ const escComma = '\0COMMA' + Math.random() + '\0';
6
+ const escPeriod = '\0PERIOD' + Math.random() + '\0';
7
+ const escSlashPattern = new RegExp(escSlash, 'g');
8
+ const escOpenPattern = new RegExp(escOpen, 'g');
9
+ const escClosePattern = new RegExp(escClose, 'g');
10
+ const escCommaPattern = new RegExp(escComma, 'g');
11
+ const escPeriodPattern = new RegExp(escPeriod, 'g');
12
+ const slashPattern = /\\\\/g;
13
+ const openPattern = /\\{/g;
14
+ const closePattern = /\\}/g;
15
+ const commaPattern = /\\,/g;
16
+ const periodPattern = /\\\./g;
17
+ export const EXPANSION_MAX = 100_000;
18
+ // `EXPANSION_MAX` caps the *number* of expansions, but not their length. An
19
+ // input like `'{a,b}'.repeat(1500)` stays under that count - its output is
20
+ // truncated to 100k results - while making every result ~1500 characters
21
+ // long. The result set, and the intermediate arrays built while combining
22
+ // brace sets, then grow large enough to exhaust memory and crash the process
23
+ // (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of
24
+ // characters the accumulator may hold at any point, so memory stays flat no
25
+ // matter how many brace groups are chained. The limit sits well above any
26
+ // realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M
27
+ // characters) so legitimate input is unaffected.
28
+ export const EXPANSION_MAX_LENGTH = 4_000_000;
29
+ function numeric(str) {
30
+ return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
31
+ }
32
+ function escapeBraces(str) {
33
+ return str
34
+ .replace(slashPattern, escSlash)
35
+ .replace(openPattern, escOpen)
36
+ .replace(closePattern, escClose)
37
+ .replace(commaPattern, escComma)
38
+ .replace(periodPattern, escPeriod);
39
+ }
40
+ function unescapeBraces(str) {
41
+ return str
42
+ .replace(escSlashPattern, '\\')
43
+ .replace(escOpenPattern, '{')
44
+ .replace(escClosePattern, '}')
45
+ .replace(escCommaPattern, ',')
46
+ .replace(escPeriodPattern, '.');
47
+ }
48
+ /**
49
+ * Basically just str.split(","), but handling cases
50
+ * where we have nested braced sections, which should be
51
+ * treated as individual members, like {a,{b,c},d}
52
+ */
53
+ function parseCommaParts(str) {
54
+ if (!str) {
55
+ return [''];
56
+ }
57
+ const parts = [];
58
+ const m = balanced('{', '}', str);
59
+ if (!m) {
60
+ return str.split(',');
61
+ }
62
+ const { pre, body, post } = m;
63
+ const p = pre.split(',');
64
+ p[p.length - 1] += '{' + body + '}';
65
+ const postParts = parseCommaParts(post);
66
+ if (post.length) {
67
+ ;
68
+ p[p.length - 1] += postParts.shift();
69
+ p.push.apply(p, postParts);
70
+ }
71
+ parts.push.apply(parts, p);
72
+ return parts;
73
+ }
74
+ export function expand(str, options = {}) {
75
+ if (!str) {
76
+ return [];
77
+ }
78
+ const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options;
79
+ // I don't know why Bash 4.3 does this, but it does.
80
+ // Anything starting with {} will have the first two bytes preserved
81
+ // but *only* at the top level, so {},a}b will not expand to anything,
82
+ // but a{},b}c will be expanded to [a}c,abc].
83
+ // One could argue that this is a bug in Bash, but since the goal of
84
+ // this module is to match Bash's rules, we escape a leading {}
85
+ if (str.slice(0, 2) === '{}') {
86
+ str = '\\{\\}' + str.slice(2);
87
+ }
88
+ return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces);
89
+ }
90
+ function embrace(str) {
91
+ return '{' + str + '}';
92
+ }
93
+ function isPadded(el) {
94
+ return /^-?0\d/.test(el);
95
+ }
96
+ function lte(i, y) {
97
+ return i <= y;
98
+ }
99
+ function gte(i, y) {
100
+ return i >= y;
101
+ }
102
+ // Build `{ acc[a] + pre + values[v] }` for every combination, capping the
103
+ // number of results at `max` and the total number of characters at `maxLength`.
104
+ // This is the one place output grows, so bounding it here keeps the single
105
+ // accumulator - and therefore memory - flat regardless of how many brace groups
106
+ // are combined (CVE-2026-14257).
107
+ function combine(acc, pre, values, max, maxLength, dropEmpties) {
108
+ const out = [];
109
+ let length = 0;
110
+ for (let a = 0; a < acc.length; a++) {
111
+ for (let v = 0; v < values.length; v++) {
112
+ if (out.length >= max)
113
+ return out;
114
+ const expansion = acc[a] + pre + values[v];
115
+ // Bash drops empty results at the top level. Skip them before they count
116
+ // against `max`, so `max` bounds the number of *kept* results.
117
+ if (dropEmpties && !expansion)
118
+ continue;
119
+ if (length + expansion.length > maxLength)
120
+ return out;
121
+ out.push(expansion);
122
+ length += expansion.length;
123
+ }
124
+ }
125
+ return out;
126
+ }
127
+ // The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
128
+ // sequence body.
129
+ function expandSequence(body, isAlphaSequence, max) {
130
+ const n = body.split(/\.\./);
131
+ const N = [];
132
+ // A sequence body always splits into two or three parts, but the compiler
133
+ // can't know that.
134
+ /* c8 ignore start */
135
+ if (n[0] === undefined || n[1] === undefined) {
136
+ return N;
137
+ }
138
+ /* c8 ignore stop */
139
+ const x = numeric(n[0]);
140
+ const y = numeric(n[1]);
141
+ const width = Math.max(n[0].length, n[1].length);
142
+ let incr = n.length === 3 && n[2] !== undefined ?
143
+ Math.max(Math.abs(numeric(n[2])), 1)
144
+ : 1;
145
+ let test = lte;
146
+ const reverse = y < x;
147
+ if (reverse) {
148
+ incr *= -1;
149
+ test = gte;
150
+ }
151
+ const pad = n.some(isPadded);
152
+ for (let i = x; test(i, y) && N.length < max; i += incr) {
153
+ let c;
154
+ if (isAlphaSequence) {
155
+ c = String.fromCharCode(i);
156
+ if (c === '\\') {
157
+ c = '';
158
+ }
159
+ }
160
+ else {
161
+ c = String(i);
162
+ if (pad) {
163
+ const need = width - c.length;
164
+ if (need > 0) {
165
+ const z = new Array(need + 1).join('0');
166
+ if (i < 0) {
167
+ c = '-' + z + c.slice(1);
168
+ }
169
+ else {
170
+ c = z + c;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ N.push(c);
176
+ }
177
+ return N;
178
+ }
179
+ function expand_(str, max, maxLength, isTop) {
180
+ // Consume the string's top-level brace groups left to right, threading a
181
+ // running set of combined prefixes (`acc`). Expanding the tail iteratively -
182
+ // rather than recursing on `m.post` once per group - keeps the native stack
183
+ // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no
184
+ // longer overflow the stack, and leaves a single accumulator whose size
185
+ // `maxLength` bounds directly (CVE-2026-14257).
186
+ let acc = [''];
187
+ // Bash drops empty results, but only when the *first* top-level group is a
188
+ // comma set - a sequence like `{a..\}` may legitimately yield ''. The drop
189
+ // is on the final strings, so it is applied to whichever `combine` produces
190
+ // them (the one with no brace set left in the tail).
191
+ let dropEmpties = false;
192
+ let firstGroup = true;
193
+ for (;;) {
194
+ const m = balanced('{', '}', str);
195
+ // No brace set left: the rest of the string is literal.
196
+ if (!m) {
197
+ return combine(acc, str, [''], max, maxLength, dropEmpties);
198
+ }
199
+ // no need to expand pre, since it is guaranteed to be free of brace-sets
200
+ const pre = m.pre;
201
+ if (/\$$/.test(pre)) {
202
+ acc = combine(acc, pre + '{' + m.body + '}', [''], max, maxLength, dropEmpties && !m.post.length);
203
+ firstGroup = false;
204
+ if (!m.post.length)
205
+ break;
206
+ str = m.post;
207
+ continue;
208
+ }
209
+ const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
210
+ const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
211
+ const isSequence = isNumericSequence || isAlphaSequence;
212
+ const isOptions = m.body.indexOf(',') >= 0;
213
+ if (!isSequence && !isOptions) {
214
+ // {a},b}
215
+ if (m.post.match(/,(?!,).*\}/)) {
216
+ str = m.pre + '{' + m.body + escClose + m.post;
217
+ isTop = true;
218
+ continue;
219
+ }
220
+ // Nothing here expands, so the whole remaining string is literal.
221
+ return combine(acc, pre + '{' + m.body + '}' + m.post, [''], max, maxLength, dropEmpties);
222
+ }
223
+ if (firstGroup) {
224
+ dropEmpties = isTop && !isSequence;
225
+ firstGroup = false;
226
+ }
227
+ let values;
228
+ if (isSequence) {
229
+ values = expandSequence(m.body, isAlphaSequence, max);
230
+ }
231
+ else {
232
+ let n = parseCommaParts(m.body);
233
+ if (n.length === 1 && n[0] !== undefined) {
234
+ // x{{a,b}}y ==> x{a}y x{b}y
235
+ n = expand_(n[0], max, maxLength, false).map(embrace);
236
+ //XXX is this necessary? Can't seem to hit it in tests.
237
+ /* c8 ignore start */
238
+ if (n.length === 1) {
239
+ acc = combine(acc, pre + n[0], [''], max, maxLength, dropEmpties && !m.post.length);
240
+ if (!m.post.length)
241
+ break;
242
+ str = m.post;
243
+ continue;
244
+ }
245
+ /* c8 ignore stop */
246
+ }
247
+ values = [];
248
+ for (let j = 0; j < n.length; j++) {
249
+ values.push.apply(values, expand_(n[j], max, maxLength, false));
250
+ }
251
+ }
252
+ acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
253
+ if (!m.post.length)
254
+ break;
255
+ str = m.post;
256
+ }
257
+ return acc;
258
+ }
259
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AAC/C,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM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,CAAC,CAAW,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;YAC3E,CAAC;QACH,CAAC;QAED,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC9E,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;YAAE,MAAK;QACzB,GAAG,GAAG,CAAC,CAAC,IAAI,CAAA;IACd,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { balanced } from 'balanced-match'\n\nconst escSlash = '\\0SLASH' + Math.random() + '\\0'\nconst escOpen = '\\0OPEN' + Math.random() + '\\0'\nconst escClose = '\\0CLOSE' + Math.random() + '\\0'\nconst escComma = '\\0COMMA' + Math.random() + '\\0'\nconst escPeriod = '\\0PERIOD' + Math.random() + '\\0'\nconst escSlashPattern = new RegExp(escSlash, 'g')\nconst escOpenPattern = new RegExp(escOpen, 'g')\nconst escClosePattern = new RegExp(escClose, 'g')\nconst escCommaPattern = new RegExp(escComma, 'g')\nconst escPeriodPattern = new RegExp(escPeriod, 'g')\nconst slashPattern = /\\\\\\\\/g\nconst openPattern = /\\\\{/g\nconst closePattern = /\\\\}/g\nconst commaPattern = /\\\\,/g\nconst periodPattern = /\\\\\\./g\n\nexport const EXPANSION_MAX = 100_000\n\n// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An\n// input like `'{a,b}'.repeat(1500)` stays under that count - its output is\n// truncated to 100k results - while making every result ~1500 characters\n// long. The result set, and the intermediate arrays built while combining\n// brace sets, then grow large enough to exhaust memory and crash the process\n// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of\n// characters the accumulator may hold at any point, so memory stays flat no\n// matter how many brace groups are chained. The limit sits well above any\n// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M\n// characters) so legitimate input is unaffected.\nexport const EXPANSION_MAX_LENGTH = 4_000_000\n\nfunction numeric(str: string) {\n return !isNaN(str as any) ? parseInt(str, 10) : str.charCodeAt(0)\n}\n\nfunction escapeBraces(str: string) {\n return str\n .replace(slashPattern, escSlash)\n .replace(openPattern, escOpen)\n .replace(closePattern, escClose)\n .replace(commaPattern, escComma)\n .replace(periodPattern, escPeriod)\n}\n\nfunction unescapeBraces(str: string) {\n return str\n .replace(escSlashPattern, '\\\\')\n .replace(escOpenPattern, '{')\n .replace(escClosePattern, '}')\n .replace(escCommaPattern, ',')\n .replace(escPeriodPattern, '.')\n}\n\n/**\n * Basically just str.split(\",\"), but handling cases\n * where we have nested braced sections, which should be\n * treated as individual members, like {a,{b,c},d}\n */\nfunction parseCommaParts(str: string) {\n if (!str) {\n return ['']\n }\n\n const parts: string[] = []\n const m = balanced('{', '}', str)\n\n if (!m) {\n return str.split(',')\n }\n\n const { pre, body, post } = m\n const p = pre.split(',')\n\n p[p.length - 1] += '{' + body + '}'\n const postParts = parseCommaParts(post)\n if (post.length) {\n ;(p[p.length - 1] as string) += postParts.shift()\n p.push.apply(p, postParts)\n }\n\n parts.push.apply(parts, p)\n\n return parts\n}\n\nexport type BraceExpansionOptions = {\n max?: number\n maxLength?: number\n}\n\nexport function expand(str: string, options: BraceExpansionOptions = {}) {\n if (!str) {\n return []\n }\n\n const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options\n\n // I don't know why Bash 4.3 does this, but it does.\n // Anything starting with {} will have the first two bytes preserved\n // but *only* at the top level, so {},a}b will not expand to anything,\n // but a{},b}c will be expanded to [a}c,abc].\n // One could argue that this is a bug in Bash, but since the goal of\n // this module is to match Bash's rules, we escape a leading {}\n if (str.slice(0, 2) === '{}') {\n str = '\\\\{\\\\}' + str.slice(2)\n }\n\n return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces)\n}\n\nfunction embrace(str: string) {\n return '{' + str + '}'\n}\n\nfunction isPadded(el: string) {\n return /^-?0\\d/.test(el)\n}\n\nfunction lte(i: number, y: number) {\n return i <= y\n}\n\nfunction gte(i: number, y: number) {\n return i >= y\n}\n\n// Build `{ acc[a] + pre + values[v] }` for every combination, capping the\n// number of results at `max` and the total number of characters at `maxLength`.\n// This is the one place output grows, so bounding it here keeps the single\n// accumulator - and therefore memory - flat regardless of how many brace groups\n// are combined (CVE-2026-14257).\nfunction combine(\n acc: string[],\n pre: string,\n values: string[],\n max: number,\n maxLength: number,\n dropEmpties: boolean,\n): string[] {\n const out: string[] = []\n let length = 0\n for (let a = 0; a < acc.length; a++) {\n for (let v = 0; v < values.length; v++) {\n if (out.length >= max) return out\n const expansion = (acc[a] as string) + pre + values[v]\n // Bash drops empty results at the top level. Skip them before they count\n // against `max`, so `max` bounds the number of *kept* results.\n if (dropEmpties && !expansion) continue\n if (length + expansion.length > maxLength) return out\n out.push(expansion)\n length += expansion.length\n }\n }\n return out\n}\n\n// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)\n// sequence body.\nfunction expandSequence(\n body: string,\n isAlphaSequence: boolean,\n max: number,\n): string[] {\n const n = body.split(/\\.\\./)\n const N: string[] = []\n // A sequence body always splits into two or three parts, but the compiler\n // can't know that.\n /* c8 ignore start */\n if (n[0] === undefined || n[1] === undefined) {\n return N\n }\n /* c8 ignore stop */\n const x = numeric(n[0])\n const y = numeric(n[1])\n const width = Math.max(n[0].length, n[1].length)\n let incr =\n n.length === 3 && n[2] !== undefined ?\n Math.max(Math.abs(numeric(n[2])), 1)\n : 1\n let test = lte\n const reverse = y < x\n if (reverse) {\n incr *= -1\n test = gte\n }\n const pad = n.some(isPadded)\n\n for (let i = x; test(i, y) && N.length < max; i += incr) {\n let c\n if (isAlphaSequence) {\n c = String.fromCharCode(i)\n if (c === '\\\\') {\n c = ''\n }\n } else {\n c = String(i)\n if (pad) {\n const need = width - c.length\n if (need > 0) {\n const z = new Array(need + 1).join('0')\n if (i < 0) {\n c = '-' + z + c.slice(1)\n } else {\n c = z + c\n }\n }\n }\n }\n N.push(c)\n }\n return N\n}\n\nfunction expand_(\n str: string,\n max: number,\n maxLength: number,\n isTop: boolean,\n): string[] {\n // Consume the string's top-level brace groups left to right, threading a\n // running set of combined prefixes (`acc`). Expanding the tail iteratively -\n // rather than recursing on `m.post` once per group - keeps the native stack\n // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no\n // longer overflow the stack, and leaves a single accumulator whose size\n // `maxLength` bounds directly (CVE-2026-14257).\n let acc: string[] = ['']\n\n // Bash drops empty results, but only when the *first* top-level group is a\n // comma set - a sequence like `{a..\\}` may legitimately yield ''. The drop\n // is on the final strings, so it is applied to whichever `combine` produces\n // them (the one with no brace set left in the tail).\n let dropEmpties = false\n let firstGroup = true\n\n for (;;) {\n const m = balanced('{', '}', str)\n\n // No brace set left: the rest of the string is literal.\n if (!m) {\n return combine(acc, str, [''], max, maxLength, dropEmpties)\n }\n\n // no need to expand pre, since it is guaranteed to be free of brace-sets\n const pre = m.pre\n\n if (/\\$$/.test(pre)) {\n acc = combine(\n acc,\n pre + '{' + m.body + '}',\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n firstGroup = false\n if (!m.post.length) break\n str = m.post\n continue\n }\n\n const isNumericSequence = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(m.body)\n const isAlphaSequence = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(\n m.body,\n )\n const isSequence = isNumericSequence || isAlphaSequence\n const isOptions = m.body.indexOf(',') >= 0\n if (!isSequence && !isOptions) {\n // {a},b}\n if (m.post.match(/,(?!,).*\\}/)) {\n str = m.pre + '{' + m.body + escClose + m.post\n isTop = true\n continue\n }\n // Nothing here expands, so the whole remaining string is literal.\n return combine(\n acc,\n pre + '{' + m.body + '}' + m.post,\n [''],\n max,\n maxLength,\n dropEmpties,\n )\n }\n\n if (firstGroup) {\n dropEmpties = isTop && !isSequence\n firstGroup = false\n }\n\n let values: string[]\n if (isSequence) {\n values = expandSequence(m.body, isAlphaSequence, max)\n } else {\n let n = parseCommaParts(m.body)\n if (n.length === 1 && n[0] !== undefined) {\n // x{{a,b}}y ==> x{a}y x{b}y\n n = expand_(n[0], max, maxLength, false).map(embrace)\n //XXX is this necessary? Can't seem to hit it in tests.\n /* c8 ignore start */\n if (n.length === 1) {\n acc = combine(\n acc,\n pre + n[0],\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n if (!m.post.length) break\n str = m.post\n continue\n }\n /* c8 ignore stop */\n }\n\n values = []\n for (let j = 0; j < n.length; j++) {\n values.push.apply(values, expand_(n[j] as string, max, maxLength, false))\n }\n }\n\n acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length)\n if (!m.post.length) break\n str = m.post\n }\n\n return acc\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }