Skip to content

Commit

Permalink
readline: fix to not access a property on an undefined value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cola119 authored and targos committed Jul 12, 2022
1 parent 1617a46 commit e9574f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/readline/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ function* emitKeys(stream) {

// This runs in O(n log n).
function commonPrefix(strings) {
if (strings.length === 0) {
return '';
}
if (strings.length === 1) {
return strings[0];
}
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-repl-tab-complete-on-editor-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

require('../common');
const ArrayStream = require('../common/arraystream');
const repl = require('repl');

const stream = new ArrayStream();
const replServer = repl.start({
input: stream,
output: stream,
terminal: true,
});

// Editor mode
replServer.write('.editor\n');

// Regression test for https://github.com/nodejs/node/issues/43528
replServer.write('a');
replServer.write(null, { name: 'tab' }); // Should not throw

replServer.close();

0 comments on commit e9574f3

Please sign in to comment.