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 a04408a

Browse filesBrowse files
Fishrock123jasnell
authored andcommitted
repl: limit persistent history correctly on load
Previously the wrong end of the history was limited on load. PR-URL: #2356 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed By: Evan Lucas <evanlucas@me.com>
1 parent 788106e commit a04408a
Copy full SHA for a04408a

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎lib/internal/repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
110110
}
111111

112112
if (data) {
113-
repl.history = data.split(/[\n\r]+/).slice(-repl.historySize);
113+
repl.history = data.split(/[\n\r]+/, repl.historySize);
114114
} else if (oldHistoryPath) {
115115
// Grab data from the older pre-v3.0 JSON NODE_REPL_HISTORY_FILE format.
116116
repl._writeToOutput(
@@ -123,7 +123,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
123123
if (!Array.isArray(repl.history)) {
124124
throw new Error('Expected array, got ' + typeof repl.history);
125125
}
126-
repl.history = repl.history.slice(-repl.historySize);
126+
repl.history = repl.history.slice(0, repl.historySize);
127127
} catch (err) {
128128
if (err.code !== 'ENOENT') {
129129
return ready(
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-repl-persistent-history.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ const tests = [{
135135
expected: [prompt, prompt + '\'42\'', prompt + '\'=^.^=\'', '\'=^.^=\'\n',
136136
prompt]
137137
},
138+
{
139+
env: { NODE_REPL_HISTORY: historyPath,
140+
NODE_REPL_HISTORY_SIZE: 1 },
141+
test: [UP, UP, CLEAR],
142+
expected: [prompt, prompt + '\'you look fabulous today\'', prompt]
143+
},
144+
{
145+
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath,
146+
NODE_REPL_HISTORY_SIZE: 1 },
147+
test: [UP, UP, UP, CLEAR],
148+
expected: [prompt, convertMsg, prompt, prompt + '\'=^.^=\'', prompt]
149+
},
138150
{ // Make sure this is always the last test, since we change os.homedir()
139151
before: function mockHomedirFailure() {
140152
// Mock os.homedir() failure

0 commit comments

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