GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: limit persistent history correctly on load · nodejs/node@a04408a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • repl.js
  • test/sequential
    • test-repl-persistent-history.js
Expand file treeCollapse file tree
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)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.