Skip to content

Commit eb42c1e

Browse files
antsmartianFishrock123
authored andcommitted
repl: handle buffered string logic on finish
Looks like `clearBufferedCommand` will be called on almost all flows. Hence history was broken. PR-URL: nodejs#24389 Fixes: nodejs#24385 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 7778c03 commit eb42c1e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/readline.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ Interface.prototype.undoHistory = function() {
348348

349349
// If it's a multiline code, then add history
350350
// accordingly.
351-
Interface.prototype.multilineHistory = function() {
352-
// check if we got a multiline code
353-
if (this.multiline !== '' && this.terminal) {
351+
Interface.prototype.multilineHistory = function(clearBuffer) {
352+
// if not clear buffer, add multiline history
353+
if (!clearBuffer && this.terminal) {
354354
const dupIndex = this.history.indexOf(this.multiline);
355355
if (dupIndex !== -1) this.history.splice(dupIndex, 1);
356356
// Remove the last entered line as multiline

lib/repl.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,13 @@ function REPLServer(prompt,
667667
}
668668
}
669669

670+
// handle multiline history
671+
if (self[kBufferedCommandSymbol].length)
672+
REPLServer.super_.prototype.multilineHistory.call(self, false);
673+
else {
674+
REPLServer.super_.prototype.multilineHistory.call(self, true);
675+
}
676+
670677
// Clear buffer if no SyntaxErrors
671678
self.clearBufferedCommand();
672679
sawCtrlD = false;
@@ -773,7 +780,6 @@ exports.start = function(prompt,
773780

774781
REPLServer.prototype.clearBufferedCommand = function clearBufferedCommand() {
775782
this[kBufferedCommandSymbol] = '';
776-
REPLServer.super_.prototype.multilineHistory.call(this);
777783
};
778784

779785
REPLServer.prototype.close = function close() {

0 commit comments

Comments
 (0)