Skip to content

Commit 2fbb6a2

Browse files
authored
Revert "Backport fix for GHSA-7h2j-956f-4vf2 to v1 (#101)" (#102)
This reverts commit 0d7652e.
1 parent 0d7652e commit 2fbb6a2

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

index.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ var escOpen = '\0OPEN'+Math.random()+'\0';
88
var escClose = '\0CLOSE'+Math.random()+'\0';
99
var escComma = '\0COMMA'+Math.random()+'\0';
1010
var escPeriod = '\0PERIOD'+Math.random()+'\0';
11-
var EXPANSION_MAX = 100000;
12-
13-
module.exports.EXPANSION_MAX = EXPANSION_MAX;
1411

1512
function numeric(str) {
1613
return parseInt(str, 10) == str
@@ -65,13 +62,10 @@ function parseCommaParts(str) {
6562
return parts;
6663
}
6764

68-
function expandTop(str, options) {
65+
function expandTop(str) {
6966
if (!str)
7067
return [];
7168

72-
options = options || {};
73-
var max = options.max == null ? EXPANSION_MAX : options.max;
74-
7569
// I don't know why Bash 4.3 does this, but it does.
7670
// Anything starting with {} will have the first two bytes preserved
7771
// but *only* at the top level, so {},a}b will not expand to anything,
@@ -82,7 +76,7 @@ function expandTop(str, options) {
8276
str = '\\{\\}' + str.substr(2);
8377
}
8478

85-
return expand(escapeBraces(str), max, true).map(unescapeBraces);
79+
return expand(escapeBraces(str), true).map(unescapeBraces);
8680
}
8781

8882
function identity(e) {
@@ -103,7 +97,7 @@ function gte(i, y) {
10397
return i >= y;
10498
}
10599

106-
function expand(str, max, isTop) {
100+
function expand(str, isTop) {
107101
var expansions = [];
108102

109103
var m = balanced('{', '}', str);
@@ -117,7 +111,7 @@ function expand(str, max, isTop) {
117111
// {a},b}
118112
if (m.post.match(/,(?!,).*\}/)) {
119113
str = m.pre + '{' + m.body + escClose + m.post;
120-
return expand(str, max, true);
114+
return expand(str);
121115
}
122116
return [str];
123117
}
@@ -129,10 +123,10 @@ function expand(str, max, isTop) {
129123
n = parseCommaParts(m.body);
130124
if (n.length === 1) {
131125
// x{{a,b}}y ==> x{a}y x{b}y
132-
n = expand(n[0], max, false).map(embrace);
126+
n = expand(n[0], false).map(embrace);
133127
if (n.length === 1) {
134128
var post = m.post.length
135-
? expand(m.post, max, false)
129+
? expand(m.post, false)
136130
: [''];
137131
return post.map(function(p) {
138132
return m.pre + n[0] + p;
@@ -147,7 +141,7 @@ function expand(str, max, isTop) {
147141
// no need to expand pre, since it is guaranteed to be free of brace-sets
148142
var pre = m.pre;
149143
var post = m.post.length
150-
? expand(m.post, max, false)
144+
? expand(m.post, false)
151145
: [''];
152146

153147
var N;
@@ -191,11 +185,11 @@ function expand(str, max, isTop) {
191185
N.push(c);
192186
}
193187
} else {
194-
N = concatMap(n, function(el) { return expand(el, max, false) });
188+
N = concatMap(n, function(el) { return expand(el, false) });
195189
}
196190

197191
for (var j = 0; j < N.length; j++) {
198-
for (var k = 0; k < post.length && expansions.length < max; k++) {
192+
for (var k = 0; k < post.length; k++) {
199193
var expansion = pre + N[j] + post[k];
200194
if (!isTop || isSequence || expansion)
201195
expansions.push(expansion);

test/sequence.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,3 @@ test('alphabetic sequences with step count', function(t) {
4848
t.end();
4949
});
5050

51-
test('sequence dos', function(t) {
52-
var str = '{1..10}'.repeat(10);
53-
var expanded = expand(str);
54-
var expanded10 = expand(str, { max: 10 });
55-
56-
t.equal(expanded.length, 100000, 'expansion is limited');
57-
t.deepEqual(expanded10, [
58-
'1111111111',
59-
'1111111112',
60-
'1111111113',
61-
'1111111114',
62-
'1111111115',
63-
'1111111116',
64-
'1111111117',
65-
'1111111118',
66-
'1111111119',
67-
'11111111110'
68-
], 'custom max truncates expansion');
69-
t.equal(expanded10.length, 10, 'custom max is respected');
70-
t.end();
71-
});
72-

0 commit comments

Comments
 (0)