@zuplo/cli 7.15.6 → 7.15.7
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/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/brace-expansion/README.md +30 -0
- package/node_modules/brace-expansion/dist/commonjs/index.d.ts +2 -0
- package/node_modules/brace-expansion/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/brace-expansion/dist/commonjs/index.js +222 -36
- package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.d.ts +2 -0
- package/node_modules/brace-expansion/dist/esm/index.d.ts.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js +222 -36
- package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
- package/node_modules/brace-expansion/package.json +1 -1
- package/package.json +11 -11
|
@@ -75,6 +75,36 @@ const expansions = expand('{a,b}'.repeat(1500), {
|
|
|
75
75
|
})
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
Three more options bound the work a call does rather than its output.
|
|
79
|
+
Past each of them, the part of `str` that is left comes back literally
|
|
80
|
+
instead of being expanded, and nothing is thrown.
|
|
81
|
+
|
|
82
|
+
- `maxDepth` caps how deeply nested brace sets are followed. This is
|
|
83
|
+
limited to `1_000` by default, to prevent stack exhaustion.
|
|
84
|
+
- `maxRewrites` caps how many times Bash's `{a},b}` quirk, where a
|
|
85
|
+
brace set followed by a comma set still expands, may restart the
|
|
86
|
+
parse. This is limited to `1_000` by default.
|
|
87
|
+
- `maxSteps` caps the total work: each character the parser scans,
|
|
88
|
+
each result it builds and each sequence value it generates is one
|
|
89
|
+
step, a zero-padded value is one per character, and each string it
|
|
90
|
+
starts expanding, `str` itself or a member of a brace set, costs 16
|
|
91
|
+
more. This is limited to `20_000_000` by default, which takes well
|
|
92
|
+
under a second to spend, to prevent CPU exhaustion. Ordinary
|
|
93
|
+
patterns need a few hundred steps, and nesting to the full
|
|
94
|
+
`maxDepth` about 4 million. If you raise `max` or `maxLength`,
|
|
95
|
+
raise this too.
|
|
96
|
+
|
|
97
|
+
When `maxSteps` runs out partway, the top-level brace sets before the
|
|
98
|
+
point where it ran out stay expanded, so the result can be partly
|
|
99
|
+
expanded rather than `[str]`:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
expand('{a,b}' + '{'.repeat(10_000) + 'c,d' + '}'.repeat(10_000))
|
|
103
|
+
// ['a{{{...c,d...}}}', 'b{{{...c,d...}}}']
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Pass `Infinity` to lift any of these bounds.
|
|
107
|
+
|
|
78
108
|
Valid expansions are:
|
|
79
109
|
|
|
80
110
|
```js
|
|
@@ -2,11 +2,13 @@ export declare const EXPANSION_MAX = 100000;
|
|
|
2
2
|
export declare const EXPANSION_MAX_LENGTH = 4000000;
|
|
3
3
|
export declare const EXPANSION_MAX_DEPTH = 1000;
|
|
4
4
|
export declare const EXPANSION_MAX_REWRITES = 1000;
|
|
5
|
+
export declare const EXPANSION_MAX_STEPS = 20000000;
|
|
5
6
|
export type BraceExpansionOptions = {
|
|
6
7
|
max?: number;
|
|
7
8
|
maxLength?: number;
|
|
8
9
|
maxDepth?: number;
|
|
9
10
|
maxRewrites?: number;
|
|
11
|
+
maxSteps?: number;
|
|
10
12
|
};
|
|
11
13
|
export declare function expand(str: string, options?: BraceExpansionOptions): string[];
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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;AAU7C,eAAO,MAAM,mBAAmB,OAAQ,CAAA;AAUxC,eAAO,MAAM,sBAAsB,OAAQ,CAAA;
|
|
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;AAU7C,eAAO,MAAM,mBAAmB,OAAQ,CAAA;AAUxC,eAAO,MAAM,sBAAsB,OAAQ,CAAA;AAU3C,eAAO,MAAM,mBAAmB,WAAa,CAAA;AAgL7C,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAWD,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,YA+BtE"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EXPANSION_MAX_REWRITES = exports.EXPANSION_MAX_DEPTH = exports.EXPANSION_MAX_LENGTH = exports.EXPANSION_MAX = void 0;
|
|
3
|
+
exports.EXPANSION_MAX_STEPS = exports.EXPANSION_MAX_REWRITES = exports.EXPANSION_MAX_DEPTH = exports.EXPANSION_MAX_LENGTH = exports.EXPANSION_MAX = void 0;
|
|
4
4
|
exports.expand = expand;
|
|
5
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';
|
|
6
|
+
const escSlash = '\0SLASH' + Math.random().toFixed(16) + '\0';
|
|
7
|
+
const escOpen = '\0OPEN' + Math.random().toFixed(16) + '\0';
|
|
8
|
+
const escClose = '\0CLOSE' + Math.random().toFixed(16) + '\0';
|
|
9
|
+
const escComma = '\0COMMA' + Math.random().toFixed(16) + '\0';
|
|
10
|
+
const escPeriod = '\0PERIOD' + Math.random().toFixed(16) + '\0';
|
|
11
11
|
const escSlashPattern = new RegExp(escSlash, 'g');
|
|
12
12
|
const escOpenPattern = new RegExp(escOpen, 'g');
|
|
13
13
|
const escClosePattern = new RegExp(escClose, 'g');
|
|
@@ -48,6 +48,23 @@ exports.EXPANSION_MAX_DEPTH = 1_000;
|
|
|
48
48
|
// seconds to produce two results. `EXPANSION_MAX_REWRITES` bounds how many
|
|
49
49
|
// times the scan may restart. Real `{a},b}` input needs a handful.
|
|
50
50
|
exports.EXPANSION_MAX_REWRITES = 1_000;
|
|
51
|
+
// `EXPANSION_MAX_STEPS` bounds the work one `expand` call does, which `max`,
|
|
52
|
+
// `maxLength` and `maxDepth` don't: nested sets are rescanned at every level
|
|
53
|
+
// and chained groups each rebuild up to `max` results, so 2KB of input could
|
|
54
|
+
// block the event loop for over 30 seconds. Each character scanned, result
|
|
55
|
+
// built and sequence value generated is a step, and each `expand_` call costs
|
|
56
|
+
// `CALL_STEPS` more. Past the budget, the set being expanded and everything
|
|
57
|
+
// after it stay literal. A glob needs a few hundred steps, and nesting all the
|
|
58
|
+
// way to `EXPANSION_MAX_DEPTH` about 4M.
|
|
59
|
+
exports.EXPANSION_MAX_STEPS = 20_000_000;
|
|
60
|
+
// What one `expand_` call costs on top of what it scans and builds. Setting
|
|
61
|
+
// one up takes about as long as scanning 16 characters, and a set whose
|
|
62
|
+
// results are wrapped to be expanded again makes one call per result, each
|
|
63
|
+
// scanning and building next to nothing: 64KB of
|
|
64
|
+
// `('{{' + ','.repeat(316) + '}{' + ','.repeat(316) + '}}').repeat(n)` made
|
|
65
|
+
// 4M such calls, which spent the budget three times as slowly as anything
|
|
66
|
+
// else.
|
|
67
|
+
const CALL_STEPS = 16;
|
|
51
68
|
function numeric(str) {
|
|
52
69
|
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
53
70
|
}
|
|
@@ -73,12 +90,96 @@ function pushAll(target, items) {
|
|
|
73
90
|
target.push(items[i]);
|
|
74
91
|
}
|
|
75
92
|
}
|
|
93
|
+
// `balanced`, run on `masked` (see `maskUnmatchedOpens`), sliced from `str`
|
|
94
|
+
// and charged for the characters it walks: up to the group's `}`, or the
|
|
95
|
+
// whole string when there is no match or unmatched `{` come first, which
|
|
96
|
+
// `unmatched` then flags for masking. Once a call overdraws the budget, it
|
|
97
|
+
// and every later one return undefined, so the rest stays literal.
|
|
98
|
+
function balancedWithBudget(str, masked, budget) {
|
|
99
|
+
if (budget.remaining < 0) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const r = (0, balanced_match_1.range)('{', '}', masked);
|
|
103
|
+
const unmatched = r !== undefined && masked.indexOf('{') < r[0];
|
|
104
|
+
budget.remaining -= r && !unmatched ? r[1] + 1 : str.length;
|
|
105
|
+
if (!r || budget.remaining < 0) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
end: r[1],
|
|
110
|
+
pre: str.slice(0, r[0]),
|
|
111
|
+
body: str.slice(r[0] + 1, r[1]),
|
|
112
|
+
post: str.slice(r[1] + 1),
|
|
113
|
+
unmatched,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// `masked` with every `{` that has no matching `}` swapped for a `\0`, which
|
|
117
|
+
// keeps the length, so a scan of it still lines up with the string it was
|
|
118
|
+
// made from. Such a `{` is literal either way, but `balanced` only learns that
|
|
119
|
+
// one is unmatched by reading to the end of the string, so with one at the
|
|
120
|
+
// head of every group (`'{a,{b,c}'.repeat(n)`) each scan read the rest of the
|
|
121
|
+
// input. That was quadratic, and once the step budget charged for it, it ran
|
|
122
|
+
// out partway through and left the rest literal. A scan of the masked copy
|
|
123
|
+
// stops at the group's `}`. It is one pass, charged as such.
|
|
124
|
+
function maskUnmatchedOpens(masked, budget) {
|
|
125
|
+
budget.remaining -= masked.length;
|
|
126
|
+
const open = [];
|
|
127
|
+
for (let i = 0; i < masked.length; i++) {
|
|
128
|
+
const c = masked.charCodeAt(i);
|
|
129
|
+
if (c === 0x7b) {
|
|
130
|
+
open.push(i);
|
|
131
|
+
}
|
|
132
|
+
else if (c === 0x7d && open.length) {
|
|
133
|
+
open.pop();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
let out = '';
|
|
137
|
+
let last = 0;
|
|
138
|
+
for (let i = 0; i < open.length; i++) {
|
|
139
|
+
const at = open[i];
|
|
140
|
+
out += masked.slice(last, at) + '\0';
|
|
141
|
+
last = at + 1;
|
|
142
|
+
}
|
|
143
|
+
return out + masked.slice(last);
|
|
144
|
+
}
|
|
145
|
+
// Whether `str` has a `,` not followed by another `,`, with a `}` after it on
|
|
146
|
+
// the same line - what `/,(?!,).*\}/.test(str)` asks, answered in one pass from
|
|
147
|
+
// the end. The regex tries every `,` and backtracks through the rest of its
|
|
148
|
+
// line from each, which is quadratic, and the `{a},b}` rewrite asks again on
|
|
149
|
+
// every pass. Like a scan, it is charged for the whole string and refused if
|
|
150
|
+
// that overdraws the budget.
|
|
151
|
+
function commaSetFollows(str, budget) {
|
|
152
|
+
budget.remaining -= str.length;
|
|
153
|
+
if (budget.remaining < 0) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
// Whether a `}` follows the current position before the line ends
|
|
157
|
+
let close = false;
|
|
158
|
+
for (let i = str.length - 1; i >= 0; i--) {
|
|
159
|
+
const c = str.charCodeAt(i);
|
|
160
|
+
if (c === 0x7d) {
|
|
161
|
+
close = true;
|
|
162
|
+
}
|
|
163
|
+
else if (c === 0x0a || c === 0x0d || c === 0x2028 || c === 0x2029) {
|
|
164
|
+
// A line terminator, which `.` does not match
|
|
165
|
+
close = false;
|
|
166
|
+
}
|
|
167
|
+
else if (c === 0x2c && close && str.charCodeAt(i + 1) !== 0x2c) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
76
173
|
/**
|
|
77
174
|
* Basically just str.split(","), but handling cases
|
|
78
175
|
* where we have nested braced sections, which should be
|
|
79
176
|
* treated as individual members, like {a,{b,c},d}
|
|
177
|
+
*
|
|
178
|
+
* Returns `undefined` if the step budget runs out before the whole set is
|
|
179
|
+
* split, since splitting what is left on every comma would tear apart the
|
|
180
|
+
* nested sets it still holds.
|
|
80
181
|
*/
|
|
81
|
-
function parseCommaParts(str) {
|
|
182
|
+
function parseCommaParts(str, budget) {
|
|
82
183
|
const parts = [];
|
|
83
184
|
// Walk the brace groups iteratively. Recursing on `post` once per group let a
|
|
84
185
|
// chain of them exhaust the stack - the parsing-side counterpart to
|
|
@@ -88,7 +189,11 @@ function parseCommaParts(str) {
|
|
|
88
189
|
// The part the next chunk continues
|
|
89
190
|
let carry = '';
|
|
90
191
|
for (;;) {
|
|
91
|
-
|
|
192
|
+
// A set's body holds no unmatched `{`, so there is nothing to mask.
|
|
193
|
+
const m = balancedWithBudget(str, str, budget);
|
|
194
|
+
if (budget.remaining < 0) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
92
197
|
if (!m) {
|
|
93
198
|
const tail = str.split(',');
|
|
94
199
|
tail[0] = carry + tail[0];
|
|
@@ -108,11 +213,23 @@ function parseCommaParts(str) {
|
|
|
108
213
|
str = post;
|
|
109
214
|
}
|
|
110
215
|
}
|
|
216
|
+
// An option that is left out, or that is NaN, gets its default. Every
|
|
217
|
+
// comparison against NaN is false, so a NaN bound would never be reached:
|
|
218
|
+
// `{ maxSteps: NaN }` let 15KB of input block the event loop for 16 seconds,
|
|
219
|
+
// and `{ maxDepth: NaN }` overflowed the stack again (CVE-2026-102278). Pass
|
|
220
|
+
// `Infinity` to lift a bound.
|
|
221
|
+
function bound(value, fallback) {
|
|
222
|
+
return value === undefined || isNaN(value) ? fallback : value;
|
|
223
|
+
}
|
|
111
224
|
function expand(str, options = {}) {
|
|
112
225
|
if (!str) {
|
|
113
226
|
return [];
|
|
114
227
|
}
|
|
115
|
-
const
|
|
228
|
+
const max = bound(options.max, exports.EXPANSION_MAX);
|
|
229
|
+
const maxLength = bound(options.maxLength, exports.EXPANSION_MAX_LENGTH);
|
|
230
|
+
const maxDepth = bound(options.maxDepth, exports.EXPANSION_MAX_DEPTH);
|
|
231
|
+
const maxRewrites = bound(options.maxRewrites, exports.EXPANSION_MAX_REWRITES);
|
|
232
|
+
const maxSteps = bound(options.maxSteps, exports.EXPANSION_MAX_STEPS);
|
|
116
233
|
// I don't know why Bash 4.3 does this, but it does.
|
|
117
234
|
// Anything starting with {} will have the first two bytes preserved
|
|
118
235
|
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
@@ -122,7 +239,7 @@ function expand(str, options = {}) {
|
|
|
122
239
|
if (str.slice(0, 2) === '{}') {
|
|
123
240
|
str = '\\{\\}' + str.slice(2);
|
|
124
241
|
}
|
|
125
|
-
return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces);
|
|
242
|
+
return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, { remaining: maxSteps }, true).map(unescapeBraces);
|
|
126
243
|
}
|
|
127
244
|
function embrace(str) {
|
|
128
245
|
return '{' + str + '}';
|
|
@@ -140,30 +257,41 @@ function gte(i, y) {
|
|
|
140
257
|
// number of results at `max` and the total number of characters at `maxLength`.
|
|
141
258
|
// This is the one place output grows, so bounding it here keeps the single
|
|
142
259
|
// accumulator - and therefore memory - flat regardless of how many brace groups
|
|
143
|
-
// are combined (CVE-2026-14257).
|
|
144
|
-
|
|
260
|
+
// are combined (CVE-2026-14257). Each result built is a step, since `max` and
|
|
261
|
+
// `maxLength` bound one combination, not how many brace groups are combined.
|
|
262
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties, budget) {
|
|
145
263
|
const out = [];
|
|
146
264
|
let length = 0;
|
|
147
|
-
|
|
148
|
-
|
|
265
|
+
// Bash drops empty results at the top level, and they don't count against
|
|
266
|
+
// `max`, so `max` bounds the number of *kept* results. Only an empty
|
|
267
|
+
// `acc[a] + pre` can make one, so for those the empty values are skipped
|
|
268
|
+
// without being visited. Visiting them one at a time let a set of empties
|
|
269
|
+
// cost `acc.length * values.length` while keeping nothing.
|
|
270
|
+
let nonEmpty;
|
|
271
|
+
outer: for (let a = 0; a < acc.length; a++) {
|
|
272
|
+
const prefix = acc[a] + pre;
|
|
273
|
+
let vs = values;
|
|
274
|
+
if (dropEmpties && !prefix) {
|
|
275
|
+
if (!nonEmpty)
|
|
276
|
+
nonEmpty = values.filter(v => v);
|
|
277
|
+
vs = nonEmpty;
|
|
278
|
+
}
|
|
279
|
+
for (let v = 0; v < vs.length; v++) {
|
|
149
280
|
if (out.length >= max)
|
|
150
|
-
|
|
151
|
-
const expansion =
|
|
152
|
-
// Bash drops empty results at the top level. Skip them before they count
|
|
153
|
-
// against `max`, so `max` bounds the number of *kept* results.
|
|
154
|
-
if (dropEmpties && !expansion)
|
|
155
|
-
continue;
|
|
281
|
+
break outer;
|
|
282
|
+
const expansion = prefix + vs[v];
|
|
156
283
|
if (length + expansion.length > maxLength)
|
|
157
|
-
|
|
284
|
+
break outer;
|
|
158
285
|
out.push(expansion);
|
|
159
286
|
length += expansion.length;
|
|
160
287
|
}
|
|
161
288
|
}
|
|
289
|
+
budget.remaining -= out.length;
|
|
162
290
|
return out;
|
|
163
291
|
}
|
|
164
292
|
// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
|
|
165
|
-
// sequence body.
|
|
166
|
-
function expandSequence(body, isAlphaSequence, max, maxLength) {
|
|
293
|
+
// sequence body, or `undefined` if the step budget runs out generating them.
|
|
294
|
+
function expandSequence(body, isAlphaSequence, max, maxLength, budget) {
|
|
167
295
|
const n = body.split(/\.\./);
|
|
168
296
|
const N = [];
|
|
169
297
|
// A sequence body always splits into two or three parts, but the compiler
|
|
@@ -186,8 +314,20 @@ function expandSequence(body, isAlphaSequence, max, maxLength) {
|
|
|
186
314
|
test = gte;
|
|
187
315
|
}
|
|
188
316
|
const pad = n.some(isPadded);
|
|
317
|
+
// A padded value is built a character at a time to `width`, which the input
|
|
318
|
+
// sets, so it costs one step per character: 64KB of
|
|
319
|
+
// `('{' + '0'.repeat(100) + '..99999}').repeat(n)` took 7 seconds charged
|
|
320
|
+
// one step per value.
|
|
321
|
+
const cost = pad ? width : 1;
|
|
189
322
|
let length = 0;
|
|
190
323
|
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
324
|
+
// Each value is a step. `max` and `maxLength` bound one sequence, but a
|
|
325
|
+
// chain of them still generated up to `max` values each, however few
|
|
326
|
+
// combining could keep.
|
|
327
|
+
budget.remaining -= cost;
|
|
328
|
+
if (budget.remaining < 0) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
191
331
|
let c;
|
|
192
332
|
if (isAlphaSequence) {
|
|
193
333
|
c = String.fromCharCode(i);
|
|
@@ -217,7 +357,9 @@ function expandSequence(body, isAlphaSequence, max, maxLength) {
|
|
|
217
357
|
}
|
|
218
358
|
return N;
|
|
219
359
|
}
|
|
220
|
-
function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
360
|
+
function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, budget, isTop) {
|
|
361
|
+
// An overdraft here makes the first scan refuse, so `str` stays literal.
|
|
362
|
+
budget.remaining -= CALL_STEPS;
|
|
221
363
|
// Too deeply nested to keep following: treat the rest as literal, the same
|
|
222
364
|
// way a group that cannot expand is already handled. Truncating rather than
|
|
223
365
|
// throwing keeps `expand` total, matching `max` and `maxLength`.
|
|
@@ -240,20 +382,33 @@ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
|
240
382
|
let rewrites = 0;
|
|
241
383
|
let dropEmpties = false;
|
|
242
384
|
let firstGroup = true;
|
|
385
|
+
// `str` with its unmatched `{` masked, once a scan has run into them
|
|
386
|
+
let masked = str;
|
|
243
387
|
for (;;) {
|
|
244
|
-
const m = (
|
|
245
|
-
// No brace set left: the rest of
|
|
388
|
+
const m = balancedWithBudget(str, masked, budget);
|
|
389
|
+
// No brace set left, or no step budget left to look for one: the rest of
|
|
390
|
+
// the string is literal.
|
|
246
391
|
if (!m) {
|
|
247
|
-
return combine(acc, str, [''], max, maxLength, dropEmpties);
|
|
392
|
+
return combine(acc, str, [''], max, maxLength, dropEmpties, budget);
|
|
393
|
+
}
|
|
394
|
+
if (m.unmatched) {
|
|
395
|
+
masked = maskUnmatchedOpens(masked, budget);
|
|
248
396
|
}
|
|
249
397
|
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
250
398
|
const pre = m.pre;
|
|
399
|
+
// This set and the rest of the string, literal: for a set that cannot
|
|
400
|
+
// expand, and for one the step budget runs out on. Once it is overdrawn,
|
|
401
|
+
// every set still being expanded, at every level, stays literal like this -
|
|
402
|
+
// otherwise each level above would go on combining, and wrapping and
|
|
403
|
+
// expanding again, results the budget was too small for.
|
|
404
|
+
const literal = () => combine(acc, pre + '{' + m.body + '}' + m.post, [''], max, maxLength, dropEmpties, budget);
|
|
251
405
|
if (/\$$/.test(pre)) {
|
|
252
|
-
acc = combine(acc, pre + '{' + m.body + '}', [''], max, maxLength, dropEmpties && !m.post.length);
|
|
406
|
+
acc = combine(acc, pre + '{' + m.body + '}', [''], max, maxLength, dropEmpties && !m.post.length, budget);
|
|
253
407
|
firstGroup = false;
|
|
254
408
|
if (!m.post.length)
|
|
255
409
|
break;
|
|
256
410
|
str = m.post;
|
|
411
|
+
masked = masked.slice(m.end + 1);
|
|
257
412
|
continue;
|
|
258
413
|
}
|
|
259
414
|
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
@@ -262,14 +417,19 @@ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
|
262
417
|
const isOptions = m.body.indexOf(',') >= 0;
|
|
263
418
|
if (!isSequence && !isOptions) {
|
|
264
419
|
// {a},b}
|
|
265
|
-
if (rewrites < maxRewrites && m.post
|
|
420
|
+
if (rewrites < maxRewrites && commaSetFollows(m.post, budget)) {
|
|
266
421
|
rewrites++;
|
|
267
422
|
str = m.pre + '{' + m.body + escClose + m.post;
|
|
423
|
+
// Taking a `}` away never gives an unmatched `{` a partner, so what
|
|
424
|
+
// is masked stays unmatched. The `{` it closed can be left without
|
|
425
|
+
// one, and the next scan masks it.
|
|
426
|
+
masked =
|
|
427
|
+
masked.slice(0, m.end) + escClose + masked.slice(m.end + 1);
|
|
268
428
|
isTop = true;
|
|
269
429
|
continue;
|
|
270
430
|
}
|
|
271
431
|
// Nothing here expands, so the whole remaining string is literal.
|
|
272
|
-
return
|
|
432
|
+
return literal();
|
|
273
433
|
}
|
|
274
434
|
if (firstGroup) {
|
|
275
435
|
dropEmpties = isTop && !isSequence;
|
|
@@ -277,20 +437,36 @@ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
|
277
437
|
}
|
|
278
438
|
let values;
|
|
279
439
|
if (isSequence) {
|
|
280
|
-
values = expandSequence(m.body, isAlphaSequence, max, maxLength);
|
|
440
|
+
values = expandSequence(m.body, isAlphaSequence, max, maxLength, budget);
|
|
441
|
+
if (!values) {
|
|
442
|
+
return literal();
|
|
443
|
+
}
|
|
281
444
|
}
|
|
282
445
|
else {
|
|
283
|
-
let n = parseCommaParts(m.body);
|
|
446
|
+
let n = parseCommaParts(m.body, budget);
|
|
447
|
+
// The step budget ran out partway through the set.
|
|
448
|
+
if (!n) {
|
|
449
|
+
return literal();
|
|
450
|
+
}
|
|
284
451
|
if (n.length === 1 && n[0] !== undefined) {
|
|
285
452
|
// x{{a,b}}y ==> x{a}y x{b}y
|
|
286
|
-
n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace);
|
|
453
|
+
n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, budget, false).map(embrace);
|
|
454
|
+
// The step budget ran out expanding the set's only part.
|
|
455
|
+
if (budget.remaining < 0) {
|
|
456
|
+
return literal();
|
|
457
|
+
}
|
|
287
458
|
//XXX is this necessary? Can't seem to hit it in tests.
|
|
288
459
|
/* c8 ignore start */
|
|
289
460
|
if (n.length === 1) {
|
|
290
|
-
|
|
461
|
+
const next = combine(acc, pre + n[0], [''], max, maxLength, dropEmpties && !m.post.length, budget);
|
|
462
|
+
if (budget.remaining < 0) {
|
|
463
|
+
return literal();
|
|
464
|
+
}
|
|
465
|
+
acc = next;
|
|
291
466
|
if (!m.post.length)
|
|
292
467
|
break;
|
|
293
468
|
str = m.post;
|
|
469
|
+
masked = masked.slice(m.end + 1);
|
|
294
470
|
continue;
|
|
295
471
|
}
|
|
296
472
|
/* c8 ignore stop */
|
|
@@ -309,7 +485,11 @@ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
|
309
485
|
values = [];
|
|
310
486
|
let valuesLength = 0;
|
|
311
487
|
outer: for (let j = 0; j < n.length; j++) {
|
|
312
|
-
const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false);
|
|
488
|
+
const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, budget, false);
|
|
489
|
+
// The step budget ran out expanding a member.
|
|
490
|
+
if (budget.remaining < 0) {
|
|
491
|
+
return literal();
|
|
492
|
+
}
|
|
313
493
|
for (let k = 0; k < expanded.length; k++) {
|
|
314
494
|
const v = expanded[k];
|
|
315
495
|
if (dropsEmpties && !v)
|
|
@@ -323,10 +503,16 @@ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
|
323
503
|
}
|
|
324
504
|
}
|
|
325
505
|
}
|
|
326
|
-
|
|
506
|
+
const next = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length, budget);
|
|
507
|
+
// The step budget ran out combining the set's values in.
|
|
508
|
+
if (budget.remaining < 0) {
|
|
509
|
+
return literal();
|
|
510
|
+
}
|
|
511
|
+
acc = next;
|
|
327
512
|
if (!m.post.length)
|
|
328
513
|
break;
|
|
329
514
|
str = m.post;
|
|
515
|
+
masked = masked.slice(m.end + 1);
|
|
330
516
|
}
|
|
331
517
|
return acc;
|
|
332
518
|
}
|