Skip to content

Commit 0b09384

Browse files
authored
Backport v5.0.6 change to v1 (#111)
Co-authored-by: Siddharth Srinivasan <[email protected]>
1 parent 10c05fc commit 0b09384

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function expand(str, max, isTop) {
166166

167167
N = [];
168168

169-
for (var i = x; test(i, y); i += incr) {
169+
for (var i = x; test(i, y) && N.length < max; i += incr) {
170170
var c;
171171
if (isAlphaSequence) {
172172
c = String.fromCharCode(i);

‎test/sequence.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test('alphabetic sequences with step count', function(t) {
4848
t.end();
4949
});
5050

51-
test('sequence dos', function(t) {
51+
test('multiple sequences max', function(t) {
5252
var str = '{1..10}'.repeat(10);
5353
var expanded10 = expand(str, { max: 10 });
5454

@@ -71,3 +71,15 @@ test('sequence dos', function(t) {
7171
t.end();
7272
});
7373

74+
test('single sequence max', function(t) {
75+
const str = '{1..100000000}';
76+
var expanded = expand(str, { max: 10 });
77+
t.deepEqual(expanded,
78+
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
79+
'custom max truncates expansion');
80+
t.equal(expanded.length, 10, 'custom max is respected');
81+
82+
var large = '{1..10000}';
83+
t.equal(expand(large).length, 10000, 'default is unbounded');
84+
t.end();
85+
});

0 commit comments

Comments
 (0)