Skip to content

Commit e9574f3

Browse files
cola119targos
authored andcommitted
readline: fix to not access a property on an undefined value
PR-URL: #43543 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1617a46 commit e9574f3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/internal/readline/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ function* emitKeys(stream) {
365365

366366
// This runs in O(n log n).
367367
function commonPrefix(strings) {
368+
if (strings.length === 0) {
369+
return '';
370+
}
368371
if (strings.length === 1) {
369372
return strings[0];
370373
}
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)