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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 14cc1ab commit 8604772

File tree

3 files changed

+69
-10
lines changed

3 files changed

+69
-10
lines changed

doc/api/readline.md

+3-1
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

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
const kHistorySize = 30;
1010
const kMincrlfDelay = 100;
11-
const kMaxcrlfDelay = 2000;
1211

1312
const util = require('util');
1413
const debug = 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 (typeof completer === 'function') {

test/parallel/test-readline-interface.js

+64-6
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
const fi = new FakeInput();
4545
const rli = new readline.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+
const fi = new FakeInput();
56+
const rli = new readline.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
const fi = new FakeInput();
231242
const delay = 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+
const fi = new FakeInput();
265+
const delay = 200;
266+
const crlfDelay = 500;
267+
const rli = new readline.Interface({
268+
input: fi,
269+
output: fi,
270+
terminal: terminal,
271+
crlfDelay
272+
});
273+
let callCount = 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+
const fi = new FakeInput();
288+
const delay = 200;
289+
const crlfDelay = Infinity;
290+
const rli = new readline.Interface({
291+
input: fi,
292+
output: fi,
293+
terminal: terminal,
294+
crlfDelay
295+
});
296+
let callCount = 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 = new FakeInput();
253311
rli = new readline.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 = new FakeInput();
499557
rli = new readline.Interface({input: fi, output: null, terminal: terminal });
500558

0 commit comments

Comments
 (0)