-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Bad readline behavior with line ending characters? #4402
Comments
the node.js documentation for readline does not mention that the write function also writes the data to the input tty as if the user had typed the string (https://nodejs.org/api/readline.html#readline_rl_write_data_key). Since you are writing to tty input "Help\n" a recursion is happening where the line event is triggering itself. A stack overflow is expected. Here is a version that demonstrates that write sends the string to the input and output:
|
Re-opening this as this is a real wtf with the current behavior and the documentation. Here is a simpler reproduction of the issue: require('readline').createInterface({
input: process.stdin,
output: process.stdout
}).on('line', function(line) {
this.write("new line\n");
}); This behavior goes back to at least v0.10, so I'm not sure how this would be viewed. It's a bug fix if the documentation is supposed to be correct, but it would be changing behavior so it's kind of a semver-major thing? |
I think this is a case of bad documentation and a confusing API. If you look at how
you'll see that it operates with no problem. The code is working as it's supposed to but the documentation is definitely wrong. |
@nodejs/documentation |
Fixes: nodejs#4402 PR-URL: nodejs#8295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Fixes: #4402 PR-URL: #8295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Fixes: #4402 PR-URL: #8295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Fixes: #4402 PR-URL: #8295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Fixes: #4402 PR-URL: #8295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Fixes: #4402 PR-URL: #8295 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
How to convert scanf("%d %d", &j, &k); in c to node js? |
When including a trailing newline character (or carriage return character) in a string that is supplied to a write function, an RangeError is thrown (
RangeError: Maximum call stack size exceeded
). The following code snippet shows the context:Here is an error log I created by issuing a command that passes the console output to a text file (
npm start > console_output.txt
):The ordinary error log doesn't show the details above, only an exit status entry:
The full code:
Is this a valid behaviour of the readline module? Note again that this only happens with trailing line endings.
The text was updated successfully, but these errors were encountered: