Skip to content
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: splitted escape sequences are processed incorrectly #1403

Closed
rlidwka opened this issue Apr 12, 2015 · 6 comments
Closed

readline: splitted escape sequences are processed incorrectly #1403

rlidwka opened this issue Apr 12, 2015 · 6 comments
Labels
confirmed-bug Issues with confirmed bugs. readline Issues and PRs related to the built-in readline module.

Comments

@rlidwka
Copy link
Contributor

rlidwka commented Apr 12, 2015

I'm running io.js inside LXC container console (lxc-console) in Ubuntu 14.04 terminal.

When I press and hold an arrow key, node.js sometimes receives escape sequences splitted into multiple chunks:

$ node -e 'process.stdin.setRawMode(true);process.stdin.on("data", function(d){console.log(d)})'
<Buffer 1b 5b 44>
<Buffer 1b 5b 44>
<Buffer 1b>
<Buffer 5b 44>
<Buffer 1b 5b 44>

Here you can see \x1b[D (arrow left) is broken into \x1b + [D.

Readline doesn't handle those, because it assumes that the entire escape sequence is contained within a data chunk. So it skips escape character itself, and [D is getting printed to the terminal:

$ node
> console.log('h[Dello world')

Here is a screenshot.

Trying to find a way to fix it at the moment. Any ideas?

@brendanashworth brendanashworth added the readline Issues and PRs related to the built-in readline module. label Apr 12, 2015
@silverwind
Copy link
Contributor

I have this too on one of my Windows machines while beeing ssh'ed into a RedHat box. Curiously, it doesn't happen on any other scenarios for me, but if it does, it hugely annoying to work the repl with that bug.

@silverwind silverwind added the confirmed-bug Issues with confirmed bugs. label Apr 12, 2015
@piscisaureus
Copy link
Contributor

There isn't a trivial fix for this, but generally speaking we'd need to turn this into a streaming parser.

@silverwind
Copy link
Contributor

Any suitable userland parsers wo could borrow from?

@silverwind
Copy link
Contributor

For some reason I fail to reproduce this on the one machine that was affected by this. Maybe there's a easier way than setting up a LXC container to reproduce?

rlidwka added a commit to rlidwka/io.js that referenced this issue May 3, 2015
In certain environments escape sequences could be splitted into
multiple chunks. For example, when user presses left arrow,
`\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`).

Fixes: nodejs#1403
@rlidwka
Copy link
Contributor Author

rlidwka commented May 3, 2015

Maybe there's a easier way than setting up a LXC container to reproduce?

You can press ESC, [ and D. In io.js repl it would be three separate keys, but in bash and other shells it would be one escape sequence representing left arrow. That's an easy way.

I'm trying to fix it in #1601

rlidwka added a commit to rlidwka/io.js that referenced this issue May 9, 2015
In certain environments escape sequences could be splitted into
multiple chunks. For example, when user presses left arrow,
`\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`).

Fixes: nodejs#1403
silverwind pushed a commit that referenced this issue May 10, 2015
In certain environments escape sequences could be splitted into
multiple chunks. For example, when user presses left arrow,
`\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`).

PR-URL: #1601
Fixes: #1403
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
@silverwind
Copy link
Contributor

Fixed by aed6bce

Fishrock123 pushed a commit to Fishrock123/node that referenced this issue May 19, 2015
In certain environments escape sequences could be splitted into
multiple chunks. For example, when user presses left arrow,
`\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`).

PR-URL: nodejs#1601
Fixes: nodejs#1403
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. readline Issues and PRs related to the built-in readline module.
Projects
None yet
Development

No branches or pull requests

4 participants