Skip to content
Merged
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
7 changes: 7 additions & 0 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ describe('MongoshNodeRepl', () => {
'const a = 20'
]);
});

it('does not crash if hitting enter and then up', async() => {
input.write('\n');
await once(mongoshRepl.runtimeState().repl, 'flushHistory');
input.write(`${arrowUp}`);
await tick();
});
});
}
});
Expand Down
6 changes: 6 additions & 0 deletions packages/history/src/history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe('changeHistory', () => {
changeHistory(cloned);
expect(cloned).to.deep.equal(i);
});

it('does not modify an empty history', () => {
const i: string[] = [];
changeHistory(i);
expect(i).to.deep.equal([]);
});
});

context('when redact option is false', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/history/src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function removeCommand(history: string, redact = false): string {
* @param {boolean} redact - Option to redact sensitive info.
*/
export function changeHistory(history: string[], redact = false): void {
if (history.length === 0) return;
const hiddenCommands = new RegExp(HIDDEN_COMMANDS, 'g');

if (hiddenCommands.test(history[0])) {
Expand Down