Skip to content

Conversation

@Zohaibarif69
Copy link

Fixes a regression where setupHistoryManager() could run before
this.input was assigned, causing a crash when onHistoryFileLoaded
is present (for example, Proxy or jest.mock() inputs).

This change ensures this.input is initialized before history setup
and adds a regression test to cover the scenario.

Refs: #61526

Testing:

  • Added regression test
  • Unable to run tests locally due to Windows build issues; CI should validate

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. labels Jan 27, 2026
Comment on lines +175 to +177
let historySize;
let history;
let removeHistoryDuplicates;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hoisting these is not needed so you can keep them scoped like the original

Suggested change
let historySize;
let history;
let removeHistoryDuplicates;

Comment on lines +187 to +189
historySize = input.historySize;
history = input.history;
removeHistoryDuplicates = input.removeHistoryDuplicates;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this

Suggested change
historySize = input.historySize;
history = input.history;
removeHistoryDuplicates = input.removeHistoryDuplicates;
const historySize = input.historySize;
const history = input.history;
const removeHistoryDuplicates = input.removeHistoryDuplicates;

this[kSubstringSearch] = null;
this.output = output;
this.input = input;
this.setupHistoryManager(input);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reodering only resolve this.input being undefine but still doesn't fix accidental REPL history init where readline.createInterface(input) is not supposed to touch REPL history but setupHistoryManager(input) ends up seeing a truthy input.onHistoryFileLoaded and calls ReplHistory.initialize() anyway

const assert = require('assert');

assert.doesNotThrow(() => {
const input = new Proxy({}, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you’re proxying {} (not a real stream). this test case will throw exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants