Skip to content

Commit 37e55bf

Browse files
Azardaddaleax
authored andcommitted
readline: remove max limit of crlfDelay
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 fffd8f5 commit 37e55bf

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

doc/api/readline.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ changes:
369369
* `crlfDelay` {number} If the delay between `\r` and `\n` exceeds
370370
`crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate
371371
end-of-line input. Default to `100` milliseconds.
372-
`crlfDelay` will be coerced to `[100, 2000]` range.
372+
`crlfDelay` will be coerced to a number no less than `100`. It can be set to
373+
`Infinity`, in which case `\r` followed by `\n` will always be considered a
374+
single newline.
373375
* `removeHistoryDuplicates` {boolean} If `true`, when a new input line added
374376
to the history list duplicates an older one, this removes the older line
375377
from the list. Defaults to `false`.

lib/readline.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const {
4848

4949
const kHistorySize = 30;
5050
const kMincrlfDelay = 100;
51-
const kMaxcrlfDelay = 2000;
5251
// \r\n, \n, or \r followed by something other than \n
5352
const lineEnding = /\r?\n|\r(?!\n)/;
5453

@@ -120,8 +119,8 @@ function Interface(input, output, completer, terminal) {
120119
this.input = input;
121120
this.historySize = historySize;
122121
this.removeHistoryDuplicates = !!removeHistoryDuplicates;
123-
this.crlfDelay = Math.max(kMincrlfDelay,
124-
Math.min(kMaxcrlfDelay, crlfDelay >>> 0));
122+
this.crlfDelay = crlfDelay ?
123+
Math.max(kMincrlfDelay, crlfDelay) : kMincrlfDelay;
125124

126125
// Check arity, 2 - for async, 1 for sync
127126
if (typeof completer === 'function') {

test/parallel/test-readline-interface.js

+65-6
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,26 @@ function isWarned(emitter) {
6363
}
6464

6565
{
66-
// Maximum crlfDelay is 2000ms
66+
// set crlfDelay to float 100.5ms
6767
const fi = new FakeInput();
6868
const rli = new readline.Interface({
6969
input: fi,
7070
output: fi,
71-
crlfDelay: 1 << 30
71+
crlfDelay: 100.5
7272
});
73-
assert.strictEqual(rli.crlfDelay, 2000);
73+
assert.strictEqual(rli.crlfDelay, 100.5);
74+
rli.close();
75+
}
76+
77+
{
78+
// set crlfDelay to 5000ms
79+
const fi = new FakeInput();
80+
const rli = new readline.Interface({
81+
input: fi,
82+
output: fi,
83+
crlfDelay: 5000
84+
});
85+
assert.strictEqual(rli.crlfDelay, 5000);
7486
rli.close();
7587
}
7688

@@ -248,7 +260,7 @@ function isWarned(emitter) {
248260
rli.close();
249261

250262
// Emit two line events when the delay
251-
// between \r and \n exceeds crlfDelay
263+
// between \r and \n exceeds crlfDelay
252264
{
253265
const fi = new FakeInput();
254266
const delay = 200;
@@ -270,8 +282,55 @@ function isWarned(emitter) {
270282
}), delay * 2);
271283
}
272284

285+
// Emit one line events when the delay between \r and \n is
286+
// over the default crlfDelay but within the setting value
287+
{
288+
const fi = new FakeInput();
289+
const delay = 200;
290+
const crlfDelay = 500;
291+
const rli = new readline.Interface({
292+
input: fi,
293+
output: fi,
294+
terminal: terminal,
295+
crlfDelay
296+
});
297+
let callCount = 0;
298+
rli.on('line', function(line) {
299+
callCount++;
300+
});
301+
fi.emit('data', '\r');
302+
setTimeout(common.mustCall(() => {
303+
fi.emit('data', '\n');
304+
assert.strictEqual(callCount, 1);
305+
rli.close();
306+
}), delay);
307+
}
308+
309+
// set crlfDelay to `Infinity` is allowed
310+
{
311+
const fi = new FakeInput();
312+
const delay = 200;
313+
const crlfDelay = Infinity;
314+
const rli = new readline.Interface({
315+
input: fi,
316+
output: fi,
317+
terminal: terminal,
318+
crlfDelay
319+
});
320+
let callCount = 0;
321+
rli.on('line', function(line) {
322+
callCount++;
323+
});
324+
fi.emit('data', '\r');
325+
setTimeout(common.mustCall(() => {
326+
fi.emit('data', '\n');
327+
assert.strictEqual(callCount, 1);
328+
rli.close();
329+
}), delay);
330+
}
331+
273332
// \t when there is no completer function should behave like an ordinary
274-
// character
333+
// character
275334
fi = new FakeInput();
276335
rli = new readline.Interface({ input: fi, output: fi, terminal: true });
277336
called = false;
@@ -517,7 +576,7 @@ function isWarned(emitter) {
517576
assert.strictEqual(isWarned(process.stdout._events), false);
518577
}
519578

520-
//can create a new readline Interface with a null output arugument
579+
// can create a new readline Interface with a null output arugument
521580
fi = new FakeInput();
522581
rli = new readline.Interface({input: fi, output: null, terminal: terminal });
523582

0 commit comments

Comments
 (0)