From 7143cc7aa4ac7710372219440ea234fc82edc64a Mon Sep 17 00:00:00 2001 From: Kohei Ueno Date: Tue, 28 Jun 2022 19:10:50 +0900 Subject: [PATCH] readline: fix to not access a property on an undefined value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43543 Reviewed-By: Antoine du Hamel Reviewed-By: Tobias Nießen Reviewed-By: Yongsheng Zhang Reviewed-By: James M Snell --- lib/internal/readline/utils.js | 3 +++ .../test-repl-tab-complete-on-editor-mode.js | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/parallel/test-repl-tab-complete-on-editor-mode.js 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();