diff --git a/lib/internal/readline.js b/lib/internal/readline.js index 6fdfae04ea2e68..3a0925a28d83ff 100644 --- a/lib/internal/readline.js +++ b/lib/internal/readline.js @@ -360,7 +360,7 @@ function* emitKeys(stream) { // backspace or ctrl+h key.name = 'backspace'; key.meta = escaped; - } else if (ch === '\x1b' || (s === '\x1b')) { + } else if (s === '\x1b') { // escape key key.name = 'escape'; key.meta = escaped; @@ -380,7 +380,7 @@ function* emitKeys(stream) { key.sequence = s; - if (key.name !== undefined) { + if (s.length !== 0 && (key.name !== undefined || escaped)) { /* Named character or sequence */ stream.emit('keypress', escaped ? undefined : s, key); } else if (s.length === 1) {