From 35ae69682253ea51e59610a9a9e132c78f5e71d5 Mon Sep 17 00:00:00 2001 From: Eric Schrock Date: Mon, 20 May 2013 14:44:26 -0400 Subject: [PATCH] readline: handle input starting with control chars Handle control characters only when there is a single byte in the stream, otherwise fall through to the standard multibyte handling. --- lib/readline.js | 2 +- test/simple/test-readline-interface.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/readline.js b/lib/readline.js index 75e51f8d10..c52f3e88b2 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -941,7 +941,7 @@ function emitKey(stream, s) { key.name = 'space'; key.meta = (s.length === 2); - } else if (s <= '\x1a') { + } else if (s.length === 1 && s <= '\x1a') { // ctrl+letter key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1); key.ctrl = true; diff --git a/test/simple/test-readline-interface.js b/test/simple/test-readline-interface.js index fc20d1d212..8976b8eb28 100644 --- a/test/simple/test-readline-interface.js +++ b/test/simple/test-readline-interface.js @@ -155,6 +155,18 @@ FakeInput.prototype.end = function() {}; assert.equal(callCount, expectedLines.length - 1); rli.close(); + // \r at start of input should output blank line + fi = new FakeInput(); + rli = new readline.Interface({ input: fi, output: fi, terminal: true }); + expectedLines = ['', 'foo' ]; + callCount = 0; + rli.on('line', function(line) { + assert.equal(line, expectedLines[callCount]); + callCount++; + }); + fi.emit('data', '\rfoo\r'); + assert.equal(callCount, expectedLines.length); + rli.close(); // sending a multi-byte utf8 char over multiple writes var buf = Buffer('☮', 'utf8');