Skip to content

Commit 31c4773

Browse files
author
Michael Smith
committed
1 parent e773c77 commit 31c4773

4 files changed

Lines changed: 53 additions & 33 deletions

File tree

‎node_modules/brace-expansion/dist/commonjs/index.js‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,23 @@ function gte(i, y) {
9595
function expand_(str, max, isTop) {
9696
/** @type {string[]} */
9797
const expansions = [];
98-
const m = (0, balanced_match_1.balanced)('{', '}', str);
99-
if (!m)
100-
return [str];
101-
// no need to expand pre, since it is guaranteed to be free of brace-sets
102-
const pre = m.pre;
103-
const post = m.post.length ? expand_(m.post, max, false) : [''];
104-
if (/\$$/.test(m.pre)) {
105-
for (let k = 0; k < post.length && k < max; k++) {
106-
const expansion = pre + '{' + m.body + '}' + post[k];
107-
expansions.push(expansion);
98+
// The `{a},b}` rewrite below restarts expansion on a rewritten string with
99+
// the same `max` and `isTop = true`. Loop instead of recursing so a long run
100+
// of non-expanding `{}` groups can't exhaust the call stack.
101+
for (;;) {
102+
const m = (0, balanced_match_1.balanced)('{', '}', str);
103+
if (!m)
104+
return [str];
105+
// no need to expand pre, since it is guaranteed to be free of brace-sets
106+
const pre = m.pre;
107+
if (/\$$/.test(m.pre)) {
108+
const post = m.post.length ? expand_(m.post, max, false) : [''];
109+
for (let k = 0; k < post.length && k < max; k++) {
110+
const expansion = pre + '{' + m.body + '}' + post[k];
111+
expansions.push(expansion);
112+
}
113+
return expansions;
108114
}
109-
}
110-
else {
111115
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
112116
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
113117
const isSequence = isNumericSequence || isAlphaSequence;
@@ -116,10 +120,16 @@ function expand_(str, max, isTop) {
116120
// {a},b}
117121
if (m.post.match(/,(?!,).*\}/)) {
118122
str = m.pre + '{' + m.body + escClose + m.post;
119-
return expand_(str, max, true);
123+
isTop = true;
124+
continue;
120125
}
121126
return [str];
122127
}
128+
// Only expand post once we know this brace set actually expands. Computing
129+
// it before the early returns above expanded post a second time on every
130+
// non-expanding `{}`, which is what made inputs like `a{},{},{}...` blow up
131+
// exponentially.
132+
const post = m.post.length ? expand_(m.post, max, false) : [''];
123133
let n;
124134
if (isSequence) {
125135
n = m.body.split(/\.\./);
@@ -195,7 +205,7 @@ function expand_(str, max, isTop) {
195205
}
196206
}
197207
}
208+
return expansions;
198209
}
199-
return expansions;
200210
}
201211
//# sourceMappingURL=index.js.map

‎node_modules/brace-expansion/dist/esm/index.js‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,23 @@ function gte(i, y) {
9191
function expand_(str, max, isTop) {
9292
/** @type {string[]} */
9393
const expansions = [];
94-
const m = balanced('{', '}', str);
95-
if (!m)
96-
return [str];
97-
// no need to expand pre, since it is guaranteed to be free of brace-sets
98-
const pre = m.pre;
99-
const post = m.post.length ? expand_(m.post, max, false) : [''];
100-
if (/\$$/.test(m.pre)) {
101-
for (let k = 0; k < post.length && k < max; k++) {
102-
const expansion = pre + '{' + m.body + '}' + post[k];
103-
expansions.push(expansion);
94+
// The `{a},b}` rewrite below restarts expansion on a rewritten string with
95+
// the same `max` and `isTop = true`. Loop instead of recursing so a long run
96+
// of non-expanding `{}` groups can't exhaust the call stack.
97+
for (;;) {
98+
const m = balanced('{', '}', str);
99+
if (!m)
100+
return [str];
101+
// no need to expand pre, since it is guaranteed to be free of brace-sets
102+
const pre = m.pre;
103+
if (/\$$/.test(m.pre)) {
104+
const post = m.post.length ? expand_(m.post, max, false) : [''];
105+
for (let k = 0; k < post.length && k < max; k++) {
106+
const expansion = pre + '{' + m.body + '}' + post[k];
107+
expansions.push(expansion);
108+
}
109+
return expansions;
104110
}
105-
}
106-
else {
107111
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
108112
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
109113
const isSequence = isNumericSequence || isAlphaSequence;
@@ -112,10 +116,16 @@ function expand_(str, max, isTop) {
112116
// {a},b}
113117
if (m.post.match(/,(?!,).*\}/)) {
114118
str = m.pre + '{' + m.body + escClose + m.post;
115-
return expand_(str, max, true);
119+
isTop = true;
120+
continue;
116121
}
117122
return [str];
118123
}
124+
// Only expand post once we know this brace set actually expands. Computing
125+
// it before the early returns above expanded post a second time on every
126+
// non-expanding `{}`, which is what made inputs like `a{},{},{}...` blow up
127+
// exponentially.
128+
const post = m.post.length ? expand_(m.post, max, false) : [''];
119129
let n;
120130
if (isSequence) {
121131
n = m.body.split(/\.\./);
@@ -191,7 +201,7 @@ function expand_(str, max, isTop) {
191201
}
192202
}
193203
}
204+
return expansions;
194205
}
195-
return expansions;
196206
}
197207
//# sourceMappingURL=index.js.map

‎node_modules/brace-expansion/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "brace-expansion",
33
"description": "Brace expansion as known from sh/bash",
4-
"version": "5.0.6",
4+
"version": "5.0.7",
55
"files": [
66
"dist"
77
],
@@ -59,6 +59,6 @@
5959
"module": "./dist/esm/index.js",
6060
"repository": {
6161
"type": "git",
62-
"url": "git+ssh://git@github.com/juliangruber/brace-expansion.git"
62+
"url": "git+https://github.com/juliangruber/brace-expansion.git"
6363
}
6464
}

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,9 +2992,9 @@
29922992
"license": "ISC"
29932993
},
29942994
"node_modules/brace-expansion": {
2995-
"version": "5.0.6",
2996-
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz",
2997-
"integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==",
2995+
"version": "5.0.7",
2996+
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz",
2997+
"integrity": "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA==",
29982998
"inBundle": true,
29992999
"license": "MIT",
30003000
"dependencies": {

0 commit comments

Comments
 (0)