Sitelet https://github.com/nodejs/node/issues/1403
Skip to content

readline: splitted escape sequences are processed incorrectly #1403

Description

@rlidwka

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?

Activity

  1. added
    readlineIssues and PRs related to the built-in readline module.
    on Apr 12, 2015
  2. silverwind commented on Apr 12, 2015

    @silverwind
    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.

  3. piscisaureus commented on Apr 12, 2015

    @piscisaureus
    Contributor

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

  4. silverwind commented on Apr 13, 2015

    @silverwind
    Contributor

    Any suitable userland parsers wo could borrow from?

  5. silverwind commented on May 2, 2015

    @silverwind
    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?

  6. rlidwka commented on May 3, 2015

    @rlidwka
    ContributorAuthor

    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

  7. silverwind commented on May 10, 2015

    @silverwind
    Contributor

    Fixed by aed6bce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions