-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readline: remove max limit of crlfDelay #13497
Conversation
doc/api/readline.md
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be clearer as:
will be coerced to
100
or greater
Does this allow it to be set to |
|
@Azard A second test case would probably be preferable, I think. |
I have fixed |
lib/readline.js
Outdated
@@ -119,7 +119,8 @@ function Interface(input, output, completer, terminal) { | |||
this.input = input; | |||
this.historySize = historySize; | |||
this.removeHistoryDuplicates = !!removeHistoryDuplicates; | |||
this.crlfDelay = Math.max(kMincrlfDelay, crlfDelay >>> 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infinity >>> 0
is 0 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you fixed this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I fixed it
doc/api/readline.md
Outdated
@@ -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 to `100` or greater, `Infinity` is allowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this could be clearer.
Maybe something along the lines of:
`crlfDelay` will be coerced to an Integer no less than `100`, unless it is `Infinity`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
doc/api/readline.md
Outdated
@@ -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, 2000]` range. | |||
`crlfDelay` will be coerced to an Integer no less than `100`, unless it is | |||
`Infinity`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still call it coerced to a number
instead of to an integer
. There is no practical difference, and it allows you to drop the unless it is Infinity
bit (that can still be mentioned, but the way this is written right now it’s a bit confusing). For example:
`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.
@Azard This doesn’t need to wait for Node 9.0.0, if you feel like your pull request isn’t moving forward you can just bump this thread. |
@addaleax I have updated docs. |
doc/api/readline.md
Outdated
@@ -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 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to comment again, but it would be great if you could wrap this line around at 80 characters … if not, that can also be done while landing the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax Thank you for detail review, I forgot it :) , now I wrapped.
@Azard Thank you! “Bump this thread” means that you leave a quick comment here in this thread, asking what needs to be done (which at this point is nothing :)) for this to land or something like that. Fresh CI: https://ci.nodejs.org/job/node-test-pull-request/9406/ |
@Azard lint error caused by a new lint rule #14431. This could be fixed by lander, but always better to
|
lib/readline.js
Outdated
@@ -120,8 +119,8 @@ 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 = crlfDelay === Infinity ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, could just collapse to Math.max(kMincrlfDelay, crlfDelay);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refack This is because crlfDelay
is number type (not integer), crlfDelay >>> 0
convert float to integer, but Infinity >>> 0
is 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
being an integer might have been more important at some point in the past, but if you look at the current uses:
https://github.com/Azard/node/blob/d90647d0952091bd7053404945f1e01c57f5e98c/lib/readline.js#L412
and
https://github.com/Azard/node/blob/d90647d0952091bd7053404945f1e01c57f5e98c/lib/readline.js#L925
AFAICT treating it as just a number
should work fine... (just need to make sure it's not passed to C++ and cast to int
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this with
this.crlfDelay = crlfDelay ? Math.max(kMincrlfDelay, crlfDelay) : kMincrlfDelay;
to make sure crlfDelay
is not undefined
, and add one unit test to check this.crlfDelay
can be float number.
crlfDelay
is a pure JavaScript variable, won't pass to C++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refack Could you help me to start CI ?
@refack Thank you for your guide, I forgot sync my branch before test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@refack It seems Ubuntu arm server down, and when this PR will be merged ? this is my first commit except doc fix. |
Landed in b8e0a5e, thank you! |
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>
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>
Should this be backported to |
@MylesBorins I have raised PR #14899 |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
readline
kMaxcrlfDelay
crlfDelay
option ofreadline.createInterface
is created by #8109 .This pull request fix
Interface.prototype._ttyWrite
\r\n problem, butcrlfDelay
make some program useInterface.prototype._normalWrite
behavior unexpect.For example:
\r\n
in csv file happen to be written in two different chunk, call them chunk A and chunk B.chunk A end with
\r
, chunk B start with\n
.chunk A split into 1000 lines, each line event cost 3ms, after 3000ms, chunk B first line event emit with empty string
''
, because two chunk time gap over 2000ms, it consider\n
is a new line.The time gap over
kMaxcrlfDelay
is not rare.kMaxcrlfDelay
is meaningless in both tty write and normal write, remove it is a better design.