Skip to content

Commit 36200bc

Browse files
cola119guangwong
authored andcommitted
readline: fix to not access a property on an undefined value
PR-URL: nodejs/node#43543 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 83ed5cf commit 36200bc

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/internal/readline/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ function* emitKeys(stream) {
366366

367367
// This runs in O(n log n).
368368
function commonPrefix(strings) {
369+
if (strings.length === 0) {
370+
return '';
371+
}
369372
if (strings.length === 1) {
370373
return strings[0];
371374
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
require('../common');
4+
const ArrayStream = require('../common/arraystream');
5+
const repl = require('repl');
6+
7+
const stream = new ArrayStream();
8+
const replServer = repl.start({
9+
input: stream,
10+
output: stream,
11+
terminal: true,
12+
});
13+
14+
// Editor mode
15+
replServer.write('.editor\n');
16+
17+
// Regression test for https://github.com/nodejs/node/issues/43528
18+
replServer.write('a');
19+
replServer.write(null, { name: 'tab' }); // Should not throw
20+
21+
replServer.close();

0 commit comments

Comments
 (0)