Skip to content

Commit 8604772

Browse files
AzardMylesBorins
authored andcommitted
readline: remove max limit of crlfDelay
Backport-PR-URL: #14899 PR-URL: #13497 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 14cc1ab commit 8604772

3 files changed

Lines changed: 69 additions & 10 deletions

File tree

‎doc/api/readline.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ added: v0.1.98
362362
*`crlfDelay` {number} If the delay between `\r` and `\n` exceeds
363363
`crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate
364364
end-of-line input. Default to `100` milliseconds.
365-
`crlfDelay` will be coerced to `[100, 2000]` range.
365+
`crlfDelay` will be coerced to a number no less than `100`. It can be set to
366+
`Infinity`, in which case `\r` followed by `\n` will always be considered a
367+
single newline.
366368
*`removeHistoryDuplicates` {boolean} If `true`, when a new input line added
367369
to the history list duplicates an older one, this removes the older line
368370
from the list. Defaults to `false`.

‎lib/readline.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
constkHistorySize=30;
1010
constkMincrlfDelay=100;
11-
constkMaxcrlfDelay=2000;
1211

1312
constutil=require('util');
1413
constdebug=util.debuglog('readline');
@@ -83,8 +82,8 @@ function Interface(input, output, completer, terminal) {
8382
this.input=input;
8483
this.historySize=historySize;
8584
this.removeHistoryDuplicates=!!removeHistoryDuplicates;
86-
this.crlfDelay=Math.max(kMincrlfDelay,
87-
Math.min(kMaxcrlfDelay,crlfDelay>>>0));
85+
this.crlfDelay=crlfDelay ?
86+
Math.max(kMincrlfDelay,crlfDelay) : kMincrlfDelay;
8887

8988
// Check arity, 2 - for async, 1 for sync
9089
if(typeofcompleter==='function'){

‎test/parallel/test-readline-interface.js‎

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,25 @@ function isWarned(emitter) {
4040
}
4141

4242
{
43-
// Maximum crlfDelay is 2000ms
43+
// set crlfDelay to float 100.5ms
4444
constfi=newFakeInput();
4545
constrli=newreadline.Interface({
4646
input: fi,
4747
output: fi,
48-
crlfDelay: 1<<30
48+
crlfDelay: 100.5
4949
});
50-
assert.strictEqual(rli.crlfDelay,2000);
50+
assert.strictEqual(rli.crlfDelay,100.5);
51+
rli.close();
52+
}
53+
54+
{
55+
constfi=newFakeInput();
56+
constrli=newreadline.Interface({
57+
input: fi,
58+
output: fi,
59+
crlfDelay: 5000
60+
});
61+
assert.strictEqual(rli.crlfDelay,5000);
5162
rli.close();
5263
}
5364

@@ -225,7 +236,7 @@ function isWarned(emitter) {
225236
rli.close();
226237

227238
// Emit two line events when the delay
228-
// between \r and \n exceeds crlfDelay
239+
// between \r and \n exceeds crlfDelay
229240
{
230241
constfi=newFakeInput();
231242
constdelay=200;
@@ -247,8 +258,55 @@ function isWarned(emitter) {
247258
}),delay*2);
248259
}
249260

261+
// Emit one line events when the delay between \r and \n is
262+
// over the default crlfDelay but within the setting value
263+
{
264+
constfi=newFakeInput();
265+
constdelay=200;
266+
constcrlfDelay=500;
267+
constrli=newreadline.Interface({
268+
input: fi,
269+
output: fi,
270+
terminal: terminal,
271+
crlfDelay
272+
});
273+
letcallCount=0;
274+
rli.on('line',function(line){
275+
callCount++;
276+
});
277+
fi.emit('data','\r');
278+
setTimeout(common.mustCall(()=>{
279+
fi.emit('data','\n');
280+
assert.strictEqual(callCount,1);
281+
rli.close();
282+
}),delay);
283+
}
284+
285+
// set crlfDelay to `Infinity` is allowed
286+
{
287+
constfi=newFakeInput();
288+
constdelay=200;
289+
constcrlfDelay=Infinity;
290+
constrli=newreadline.Interface({
291+
input: fi,
292+
output: fi,
293+
terminal: terminal,
294+
crlfDelay
295+
});
296+
letcallCount=0;
297+
rli.on('line',function(line){
298+
callCount++;
299+
});
300+
fi.emit('data','\r');
301+
setTimeout(common.mustCall(()=>{
302+
fi.emit('data','\n');
303+
assert.strictEqual(callCount,1);
304+
rli.close();
305+
}),delay);
306+
}
307+
250308
// \t when there is no completer function should behave like an ordinary
251-
// character
309+
// character
252310
fi=newFakeInput();
253311
rli=newreadline.Interface({input: fi,output: fi,terminal: true});
254312
called=false;
@@ -494,7 +552,7 @@ function isWarned(emitter) {
494552
assert.strictEqual(isWarned(process.stdout._events),false);
495553
}
496554

497-
//can create a new readline Interface with a null output arugument
555+
//can create a new readline Interface with a null output arugument
498556
fi=newFakeInput();
499557
rli=newreadline.Interface({input: fi,output: null,terminal: terminal});
500558

0 commit comments

Comments
 (0)