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

Comments

Projects
None yet
4 participants
@rlidwka
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?

@silverwind

This comment has been minimized.

Show comment
Hide comment
@silverwind

silverwind Apr 12, 2015

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.

Contributor

silverwind commented Apr 12, 2015

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.

@piscisaureus

This comment has been minimized.

Show comment
Hide comment
@piscisaureus

piscisaureus Apr 12, 2015

Member

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

Member

piscisaureus commented Apr 12, 2015

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

@silverwind

This comment has been minimized.

Show comment
Hide comment
@silverwind

silverwind Apr 13, 2015

Contributor

Any suitable userland parsers wo could borrow from?

Contributor

silverwind commented Apr 13, 2015

Any suitable userland parsers wo could borrow from?

@silverwind

This comment has been minimized.

Show comment
Hide comment
@silverwind

silverwind May 2, 2015

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?

Contributor

silverwind commented May 2, 2015

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

readline: turn emitKeys into a streaming parser
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

This comment has been minimized.

Show comment
Hide comment
@rlidwka

rlidwka May 3, 2015

Contributor

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

Contributor

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

readline: turn emitKeys into a streaming parser
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 added a commit that referenced this issue May 10, 2015

readline: turn emitKeys into a streaming parser
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

This comment has been minimized.

Show comment
Hide comment
@silverwind

silverwind May 10, 2015

Contributor

Fixed by aed6bce

Contributor

silverwind commented May 10, 2015

Fixed by aed6bce

@silverwind silverwind closed this May 10, 2015

Fishrock123 added a commit to Fishrock123/node that referenced this issue May 19, 2015

readline: turn emitKeys into a streaming parser
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