Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/repl/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ReplHistory {
if (this[kHistory].length === 0 || this[kHistory][0] !== normalizedLine) {
if (this[kRemoveHistoryDuplicates]) {
// Remove older history line if identical to new one
const dupIndex = ArrayPrototypeIndexOf(this[kHistory], line);
const dupIndex = ArrayPrototypeIndexOf(this[kHistory], normalizedLine);
if (dupIndex !== -1) ArrayPrototypeSplice(this[kHistory], dupIndex, 1);
}

Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-repl-history-dedup-multiline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

const common = require('../common');

if (process.env.TERM === 'dumb') {
common.skip('skipping - dumb terminal');
}

const assert = require('assert');
const readline = require('readline');
const { EventEmitter } = require('events');

class FakeInput extends EventEmitter {
resume() {}
pause() {}
write() {}
end() {}
}
FakeInput.prototype.readable = true;

{
const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: true,
removeHistoryDuplicates: true,
});

function submitLine(line) {
rli.line = line;
fi.emit('keypress', '', { name: 'enter' });
}

submitLine('line1\nline2');
submitLine('other');
submitLine('line1\nline2');

assert.strictEqual(rli.history.length, 2);
assert.strictEqual(rli.history[0], 'line2\rline1');
assert.strictEqual(rli.history[1], 'other');

rli.close();
}
Loading