From d558055f7402ff8bb104c15529a2cc2111b9383c Mon Sep 17 00:00:00 2001 From: cola119 Date: Thu, 23 Jun 2022 14:50:31 +0900 Subject: [PATCH] readline: fix to not access a property on an undefined value --- 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..165230ae79ecca --- /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();