-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
repl: make sure historyPath is trimmed #4539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,15 +55,26 @@ function createRepl(env, opts, cb) { | |
} | ||
|
||
const repl = REPL.start(opts); | ||
if (opts.terminal && env.NODE_REPL_HISTORY !== '') { | ||
if (opts.terminal) { | ||
return setupHistory(repl, env.NODE_REPL_HISTORY, | ||
env.NODE_REPL_HISTORY_FILE, cb); | ||
} | ||
|
||
repl._historyPrev = _replHistoryMessage; | ||
cb(null, repl); | ||
} | ||
|
||
function setupHistory(repl, historyPath, oldHistoryPath, ready) { | ||
// Empty string disables persistent history. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want to do if (typeof historyPath === 'string')
historyPath = historyPath.trim(); Then drop the condition that is currently on line 74. |
||
|
||
if (typeof historyPath === 'string') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait what else would it be? We don't export There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if process.env.NODE_REPL_HISTORY is undefined, then it will be undefined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, carry on. |
||
historyPath = historyPath.trim(); | ||
|
||
if (historyPath === '') { | ||
repl._historyPrev = _replHistoryMessage; | ||
return ready(null, repl); | ||
} | ||
|
||
if (!historyPath) { | ||
try { | ||
historyPath = path.join(os.homedir(), '.node_repl_history'); | ||
|
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.
I wonder if it wouldn't be more DRY if the logic was moved out to here. We can make
var historyPath = env.NODE_REPL_HISTORY
up here so we don't access the env programmatically multiple times.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.
That was how I had originally done this, but changed it at @cjihrig's request. I'm fine doing it either though
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.
My reasoning is that empty string is a magic value with
setupHistory()
, so it would make more sense to keep it there. Also, if this function ever gets called from anywhere else, the same logic would have to be duplicated.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.
That makes sense to me and seems like it would be easier to maintain. That work for you @Fishrock123?
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.
fair enough, no strong opinion