diff --git a/lib/internal/readline/utils.js b/lib/internal/readline/utils.js index 55b3e07b4c1782..98679494a3e64b 100644 --- a/lib/internal/readline/utils.js +++ b/lib/internal/readline/utils.js @@ -366,6 +366,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]; } diff --git a/test/parallel/test-repl-tab-complete-on-editor-mode.js b/test/parallel/test-repl-tab-complete-on-editor-mode.js new file mode 100644 index 00000000000000..610724de2a2844 --- /dev/null +++ b/test/parallel/test-repl-tab-complete-on-editor-mode.js @@ -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();