Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 26f0240

Browse filesBrowse files
evanlucasMyles Borins
authored andcommitted
repl: make sure historyPath is trimmed
If one were to set NODE_REPL_HISTORY to a string that contains only a space (" "), then the history file would be created with that name which can cause problems are certain systems. PR-URL: #4539 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 3d5bc69 commit 26f0240
Copy full SHA for 26f0240

File tree

Expand file treeCollapse file tree

3 files changed

+18
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+18
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/repl.markdown‎

Copy file name to clipboardExpand all lines: doc/api/repl.markdown
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ via the following environment variables:
3737
- `NODE_REPL_HISTORY` - When a valid path is given, persistent REPL history
3838
will be saved to the specified file rather than `.node_repl_history` in the
3939
user's home directory. Setting this value to `""` will disable persistent
40-
REPL history.
40+
REPL history. Whitespace will be trimmed from the value.
4141
- `NODE_REPL_HISTORY_SIZE` - defaults to `1000`. Controls how many lines of
4242
history will be persisted if history is available. Must be a positive number.
4343
- `NODE_REPL_MODE` - may be any of `sloppy`, `strict`, or `magic`. Defaults
Collapse file

‎lib/internal/repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl.js
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,26 @@ function createRepl(env, opts, cb) {
5555
}
5656

5757
const repl = REPL.start(opts);
58-
if (opts.terminal && env.NODE_REPL_HISTORY !== '') {
58+
if (opts.terminal) {
5959
return setupHistory(repl, env.NODE_REPL_HISTORY,
6060
env.NODE_REPL_HISTORY_FILE, cb);
6161
}
62+
6263
repl._historyPrev = _replHistoryMessage;
6364
cb(null, repl);
6465
}
6566

6667
function setupHistory(repl, historyPath, oldHistoryPath, ready) {
68+
// Empty string disables persistent history.
69+
70+
if (typeof historyPath === 'string')
71+
historyPath = historyPath.trim();
72+
73+
if (historyPath === '') {
74+
repl._historyPrev = _replHistoryMessage;
75+
return ready(null, repl);
76+
}
77+
6778
if (!historyPath) {
6879
try {
6980
historyPath = path.join(os.homedir(), '.node_repl_history');
Collapse file

‎test/parallel/test-repl-persistent-history.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-persistent-history.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ const tests = [
8585
test: [UP],
8686
expected: [prompt, replDisabled, prompt]
8787
},
88+
{
89+
env: { NODE_REPL_HISTORY: ' ' },
90+
test: [UP],
91+
expected: [prompt, replDisabled, prompt]
92+
},
8893
{
8994
env: { NODE_REPL_HISTORY: '',
9095
NODE_REPL_HISTORY_FILE: enoentHistoryPath },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.