Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ function InterfaceConstructor(input, output, completer, terminal) {
};
}

this.setupHistoryManager(historyOptions ?? input);
// When only a stream is given, its own properties are not history options.
this.setupHistoryManager(historyOptions ?? { __proto__: null });

if (completer !== undefined && typeof completer !== 'function') {
throw new ERR_INVALID_ARG_VALUE('completer', completer);
Expand Down
45 changes: 45 additions & 0 deletions test/parallel/test-readline-input-stream-history-props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

// This tests that readline.createInterface(stream) does not read REPL history
// options from the input stream itself. A stream that happens to have an
// onHistoryFileLoaded property, for example a mock, used to start REPL history
// loading before the interface was set up and threw a TypeError.
// Refs: https://github.com/nodejs/node/issues/61526

const common = require('../common');
const assert = require('assert');
const readline = require('readline');
const { PassThrough } = require('stream');

{
const input = new PassThrough();
input.onHistoryFileLoaded = common.mustNotCall();
const rl = readline.createInterface(input);
assert.deepStrictEqual(rl.history, []);
rl.close();
}

{
const input = new PassThrough();
input.onHistoryFileLoaded = common.mustNotCall();
const rl = readline.createInterface({ input });
rl.close();
}

// Properties of the stream with the names of history options are ignored.
{
const input = new PassThrough();
input.history = 'not an array';
input.size = -1;
const rl = readline.createInterface(input);
assert.deepStrictEqual(rl.history, []);
rl.close();
}

// History passed in an options object still works.
{
const input = new PassThrough();
const rl = readline.createInterface({ input, history: ['b', 'a'] });
assert.deepStrictEqual(rl.history, ['b', 'a']);
rl.close();
}
Loading