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 676e9da

Browse filesBrowse files
committed
repl: fix dedup comparing normalized line against raw history
Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com> PR-URL: #62886 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6482073 commit 676e9da
Copy full SHA for 676e9da

2 files changed

+45-1Lines changed: 45 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/repl/history.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl/history.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ReplHistory {
142142
if (this[kHistory].length === 0 || this[kHistory][0] !== normalizedLine) {
143143
if (this[kRemoveHistoryDuplicates]) {
144144
// Remove older history line if identical to new one
145-
const dupIndex = ArrayPrototypeIndexOf(this[kHistory], line);
145+
const dupIndex = ArrayPrototypeIndexOf(this[kHistory], normalizedLine);
146146
if (dupIndex !== -1) ArrayPrototypeSplice(this[kHistory], dupIndex, 1);
147147
}
148148

Collapse file
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (process.env.TERM === 'dumb') {
6+
common.skip('skipping - dumb terminal');
7+
}
8+
9+
const assert = require('assert');
10+
const readline = require('readline');
11+
const { EventEmitter } = require('events');
12+
13+
class FakeInput extends EventEmitter {
14+
resume() {}
15+
pause() {}
16+
write() {}
17+
end() {}
18+
}
19+
FakeInput.prototype.readable = true;
20+
21+
{
22+
const fi = new FakeInput();
23+
const rli = new readline.Interface({
24+
input: fi,
25+
output: fi,
26+
terminal: true,
27+
removeHistoryDuplicates: true,
28+
});
29+
30+
function submitLine(line) {
31+
rli.line = line;
32+
fi.emit('keypress', '', { name: 'enter' });
33+
}
34+
35+
submitLine('line1\nline2');
36+
submitLine('other');
37+
submitLine('line1\nline2');
38+
39+
assert.strictEqual(rli.history.length, 2);
40+
assert.strictEqual(rli.history[0], 'line2\rline1');
41+
assert.strictEqual(rli.history[1], 'other');
42+
43+
rli.close();
44+
}

0 commit comments

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