From e1038fab431f2c4f0a42be26e5f58bffc463cd29 Mon Sep 17 00:00:00 2001 From: Azard <330815461@qq.com> Date: Tue, 6 Jun 2017 20:22:22 +0800 Subject: [PATCH 1/8] readline: remove max limit of crlfDelay --- doc/api/readline.md | 2 +- lib/readline.js | 4 +-- test/parallel/test-readline-interface.js | 36 ++++++++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index 767f8ccefcd248..21157fa3751644 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -369,7 +369,7 @@ changes: * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate end-of-line input. Default to `100` milliseconds. - `crlfDelay` will be coerced to `[100, 2000]` range. + `crlfDelay` will be coerced not less than `100` milliseconds. * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Defaults to `false`. diff --git a/lib/readline.js b/lib/readline.js index fb6ffb8f060a33..1470a1de609cad 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -50,7 +50,6 @@ const { const kHistorySize = 30; const kMincrlfDelay = 100; -const kMaxcrlfDelay = 2000; // \r\n, \n, or \r followed by something other than \n const lineEnding = /\r?\n|\r(?!\n)/; @@ -125,8 +124,7 @@ function Interface(input, output, completer, terminal) { this.input = input; this.historySize = historySize; this.removeHistoryDuplicates = !!removeHistoryDuplicates; - this.crlfDelay = Math.max(kMincrlfDelay, - Math.min(kMaxcrlfDelay, crlfDelay >>> 0)); + this.crlfDelay = Math.max(kMincrlfDelay, crlfDelay >>> 0); // Check arity, 2 - for async, 1 for sync if (typeof completer === 'function') { diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 9ce978b86ed476..f744722a1ea377 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -63,14 +63,14 @@ function isWarned(emitter) { } { - // Maximum crlfDelay is 2000ms + // set crlfDelay to 5000ms const fi = new FakeInput(); const rli = new readline.Interface({ input: fi, output: fi, - crlfDelay: 1 << 30 + crlfDelay: 5000 }); - assert.strictEqual(rli.crlfDelay, 2000); + assert.strictEqual(rli.crlfDelay, 5000); rli.close(); } @@ -248,7 +248,7 @@ function isWarned(emitter) { rli.close(); // Emit two line events when the delay - // between \r and \n exceeds crlfDelay + // between \r and \n exceeds crlfDelay { const fi = new FakeInput(); const delay = 200; @@ -270,8 +270,32 @@ function isWarned(emitter) { }), delay * 2); } + // Emit one line events when the delay between \r and \n is + // over the default crlfDelay but within the setting value + { + const fi = new FakeInput(); + const delay = 200; + const crlfDelay = 500; + const rli = new readline.Interface({ + input: fi, + output: fi, + terminal: terminal, + crlfDelay + }); + let callCount = 0; + rli.on('line', function(line) { + callCount++; + }); + fi.emit('data', '\r'); + setTimeout(common.mustCall(() => { + fi.emit('data', '\n'); + assert.strictEqual(callCount, 1); + rli.close(); + }), delay); + } + // \t when there is no completer function should behave like an ordinary - // character + // character fi = new FakeInput(); rli = new readline.Interface({ input: fi, output: fi, terminal: true }); called = false; @@ -513,7 +537,7 @@ function isWarned(emitter) { assert.strictEqual(isWarned(process.stdout._events), false); } - //can create a new readline Interface with a null output arugument + // can create a new readline Interface with a null output arugument fi = new FakeInput(); rli = new readline.Interface({ input: fi, output: null, terminal: terminal }); From 056999e81c781a0a431912a5b468547b10d3831f Mon Sep 17 00:00:00 2001 From: Weilun Xiong <330815461@qq.com> Date: Wed, 7 Jun 2017 00:10:22 +0800 Subject: [PATCH 2/8] doc: api/readline.md clearer --- doc/api/readline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index 21157fa3751644..981f96b032c634 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -369,7 +369,7 @@ changes: * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate end-of-line input. Default to `100` milliseconds. - `crlfDelay` will be coerced not less than `100` milliseconds. + `crlfDelay` will be coerced to `100` or greater. * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Defaults to `false`. From b97c9c41077bdf1a9170097acf9074ad2a930ee5 Mon Sep 17 00:00:00 2001 From: Azard <330815461@qq.com> Date: Wed, 7 Jun 2017 01:43:55 +0800 Subject: [PATCH 3/8] readline: set crlfDelay to Infinity is allowed --- doc/api/readline.md | 2 +- lib/readline.js | 3 ++- test/parallel/test-readline-interface.js | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index 981f96b032c634..9f5c713a929b4c 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -369,7 +369,7 @@ changes: * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate end-of-line input. Default to `100` milliseconds. - `crlfDelay` will be coerced to `100` or greater. + `crlfDelay` will be coerced to `100` or greater, `Infinity` is allowed. * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Defaults to `false`. diff --git a/lib/readline.js b/lib/readline.js index 1470a1de609cad..a6ba51b924dcec 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -124,7 +124,8 @@ function Interface(input, output, completer, terminal) { this.input = input; this.historySize = historySize; this.removeHistoryDuplicates = !!removeHistoryDuplicates; - this.crlfDelay = Math.max(kMincrlfDelay, crlfDelay >>> 0); + this.crlfDelay = crlfDelay === Infinity ? + Infinity : Math.max(kMincrlfDelay, crlfDelay >>> 0); // Check arity, 2 - for async, 1 for sync if (typeof completer === 'function') { diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index f744722a1ea377..aab86ee5184aaf 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -294,6 +294,29 @@ function isWarned(emitter) { }), delay); } + // set crlfDelay to `Infinity` is allowed + { + const fi = new FakeInput(); + const delay = 200; + const crlfDelay = Infinity; + const rli = new readline.Interface({ + input: fi, + output: fi, + terminal: terminal, + crlfDelay + }); + let callCount = 0; + rli.on('line', function(line) { + callCount++; + }); + fi.emit('data', '\r'); + setTimeout(common.mustCall(() => { + fi.emit('data', '\n'); + assert.strictEqual(callCount, 1); + rli.close(); + }), delay); + } + // \t when there is no completer function should behave like an ordinary // character fi = new FakeInput(); From f786414e0b039799348ca22aa7a453aaffba2c76 Mon Sep 17 00:00:00 2001 From: Azard <330815461@qq.com> Date: Wed, 7 Jun 2017 12:56:03 +0800 Subject: [PATCH 4/8] doc: clearer --- doc/api/readline.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index 9f5c713a929b4c..e8bfe3990c1dd9 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -369,7 +369,8 @@ changes: * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate end-of-line input. Default to `100` milliseconds. - `crlfDelay` will be coerced to `100` or greater, `Infinity` is allowed. + `crlfDelay` will be coerced to an Integer no less than `100`, unless it is + `Infinity`. * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Defaults to `false`. From 43b78ec541c5f35c47168d746bd69dbacf87b4ff Mon Sep 17 00:00:00 2001 From: Azard Date: Sun, 30 Jul 2017 18:36:27 +0800 Subject: [PATCH 5/8] update doc --- doc/api/readline.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index e8bfe3990c1dd9..8f0e76a7a0c906 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -369,8 +369,7 @@ changes: * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate end-of-line input. Default to `100` milliseconds. - `crlfDelay` will be coerced to an Integer no less than `100`, unless it is - `Infinity`. + `crlfDelay` will be coerced to a number no less than `100`. It can be set to `Infinity`, in which case `\r` followed by `\n` will always be considered a single newline. * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Defaults to `false`. From d7c1873f26ffa39dfea22edf131660de2dd157a5 Mon Sep 17 00:00:00 2001 From: Azard Date: Sun, 30 Jul 2017 23:32:11 +0800 Subject: [PATCH 6/8] wrap line around 80 chars --- doc/api/readline.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index 8f0e76a7a0c906..085ac885401c89 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -369,7 +369,9 @@ changes: * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate end-of-line input. Default to `100` milliseconds. - `crlfDelay` will be coerced to a number no less than `100`. It can be set to `Infinity`, in which case `\r` followed by `\n` will always be considered a single newline. + `crlfDelay` will be coerced to a number no less than `100`. It can be set to + `Infinity`, in which case `\r` followed by `\n` will always be considered a + single newline. * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Defaults to `false`. From d90647d0952091bd7053404945f1e01c57f5e98c Mon Sep 17 00:00:00 2001 From: Azard Date: Mon, 31 Jul 2017 01:53:10 +0800 Subject: [PATCH 7/8] fix ident lint error --- lib/readline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/readline.js b/lib/readline.js index a6ba51b924dcec..27c101d3053321 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -125,7 +125,7 @@ function Interface(input, output, completer, terminal) { this.historySize = historySize; this.removeHistoryDuplicates = !!removeHistoryDuplicates; this.crlfDelay = crlfDelay === Infinity ? - Infinity : Math.max(kMincrlfDelay, crlfDelay >>> 0); + Infinity : Math.max(kMincrlfDelay, crlfDelay >>> 0); // Check arity, 2 - for async, 1 for sync if (typeof completer === 'function') { From 3d9c7a9a1f2e50e0e86c1db7c0509db2f8153501 Mon Sep 17 00:00:00 2001 From: Azard Date: Mon, 31 Jul 2017 15:51:48 +0800 Subject: [PATCH 8/8] crlfDelay is number, not convert to int --- lib/readline.js | 4 ++-- test/parallel/test-readline-interface.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 27c101d3053321..57f9e7d6e8c849 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -124,8 +124,8 @@ function Interface(input, output, completer, terminal) { this.input = input; this.historySize = historySize; this.removeHistoryDuplicates = !!removeHistoryDuplicates; - this.crlfDelay = crlfDelay === Infinity ? - Infinity : Math.max(kMincrlfDelay, crlfDelay >>> 0); + this.crlfDelay = crlfDelay ? + Math.max(kMincrlfDelay, crlfDelay) : kMincrlfDelay; // Check arity, 2 - for async, 1 for sync if (typeof completer === 'function') { diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index aab86ee5184aaf..e73481d4298f1d 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -62,6 +62,18 @@ function isWarned(emitter) { rli.close(); } +{ + // set crlfDelay to float 100.5ms + const fi = new FakeInput(); + const rli = new readline.Interface({ + input: fi, + output: fi, + crlfDelay: 100.5 + }); + assert.strictEqual(rli.crlfDelay, 100.5); + rli.close(); +} + { // set crlfDelay to 5000ms const fi = new FakeInput();