Skip to content

Commit 35ae696

Browse files
Eric Schrocktjfontaine
authored andcommitted
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.
1 parent 7c554a5 commit 35ae696

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/readline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ function emitKey(stream, s) {
941941
key.name = 'space';
942942
key.meta = (s.length === 2);
943943

944-
} else if (s <= '\x1a') {
944+
} else if (s.length === 1 && s <= '\x1a') {
945945
// ctrl+letter
946946
key.name = String.fromCharCode(s.charCodeAt(0) + 'a'.charCodeAt(0) - 1);
947947
key.ctrl = true;

test/simple/test-readline-interface.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ FakeInput.prototype.end = function() {};
155155
assert.equal(callCount, expectedLines.length - 1);
156156
rli.close();
157157

158+
// \r at start of input should output blank line
159+
fi = new FakeInput();
160+
rli = new readline.Interface({ input: fi, output: fi, terminal: true });
161+
expectedLines = ['', 'foo' ];
162+
callCount = 0;
163+
rli.on('line', function(line) {
164+
assert.equal(line, expectedLines[callCount]);
165+
callCount++;
166+
});
167+
fi.emit('data', '\rfoo\r');
168+
assert.equal(callCount, expectedLines.length);
169+
rli.close();
158170

159171
// sending a multi-byte utf8 char over multiple writes
160172
var buf = Buffer('☮', 'utf8');

0 commit comments

Comments
 (0)