-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
readline: initialize input before history manager #61538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
lib/internal/readline/interface.js
Outdated
| let historySize; | ||
| let history; | ||
| let removeHistoryDuplicates; |
There was a problem hiding this comment.
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
| let historySize; | |
| let history; | |
| let removeHistoryDuplicates; |
lib/internal/readline/interface.js
Outdated
| historySize = input.historySize; | ||
| history = input.history; | ||
| removeHistoryDuplicates = input.removeHistoryDuplicates; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this
| 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); |
There was a problem hiding this comment.
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({}, { |
There was a problem hiding this comment.
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
|
@thisalihassan Thanks for the feedback! I’ll address the scoping, test, and history initialization issues and update the PR shortly. |
736d855 to
e3a00ce
Compare
|
@thisalihassan Thanks — I’ve addressed the scoping, history initialization, and test issues you mentioned. |
e3a00ce to
9dc21a9
Compare
|
@thisalihassan I’ve cleaned up the diff, reverted the unnecessary scoping changes, fixed the history initialization logic, and updated the test to use real streams. |
Fixes a regression where
setupHistoryManager()could run beforethis.inputwas assigned, causing a crash whenonHistoryFileLoadedis present (for example, Proxy or
jest.mock()inputs).This change ensures
this.inputis initialized before history setupand adds a regression test to cover the scenario.
Refs: #61526
Testing: