GeezerVison is showing github.com — repl: limit persistent history correctly on load · nodejs/node@a04408a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/repl.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,7 +110,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { | 110 | 110 | } | 111 | 111 |
| 112 | 112 | if (data) { | 113 | | - repl.history = data.split(/[\n\r]+/).slice(-repl.historySize); | | 113 | + repl.history = data.split(/[\n\r]+/, repl.historySize); | 114 | 114 | } else if (oldHistoryPath) { | 115 | 115 | // Grab data from the older pre-v3.0 JSON NODE_REPL_HISTORY_FILE format. | 116 | 116 | repl._writeToOutput( | @@ -123,7 +123,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { | 123 | 123 | if (!Array.isArray(repl.history)) { | 124 | 124 | throw new Error('Expected array, got ' + typeof repl.history); | 125 | 125 | } | 126 | | - repl.history = repl.history.slice(-repl.historySize); | | 126 | + repl.history = repl.history.slice(0, repl.historySize); | 127 | 127 | } catch (err) { | 128 | 128 | if (err.code !== 'ENOENT') { | 129 | 129 | return ready( | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-repl-persistent-history.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -135,6 +135,18 @@ const tests = [{ | 135 | 135 | expected: [prompt, prompt + '\'42\'', prompt + '\'=^.^=\'', '\'=^.^=\'\n', | 136 | 136 | prompt] | 137 | 137 | }, | | 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 | +}, | 138 | 150 | { // Make sure this is always the last test, since we change os.homedir() | 139 | 151 | before: function mockHomedirFailure() { | 140 | 152 | // Mock os.homedir() failure | |
|