diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index bc8f30427616..c9a7f5a379b3 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -889,7 +889,7 @@ class Interface extends InterfaceConstructor { if (this.cursor < this.line.length) { this[kBeforeEdit](this.line, this.cursor); const trailing = StringPrototypeSlice(this.line, this.cursor); - const match = RegExpPrototypeExec(/^(?:\s+|\W+|\w+)\s*/, trailing); + const match = RegExpPrototypeExec(/^(?:\s+|[^\w\s]+|\w+)\s*/, trailing); this.line = StringPrototypeSlice(this.line, 0, this.cursor) + StringPrototypeSlice(trailing, match[0].length); diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 2fd4646c314c..77c09d56bb51 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -593,6 +593,19 @@ function assertCursorRowsAndCols(rli, rows, cols) { fi.emit('keypress', '.', deleteWordRightKey); fi.emit('data', '\n'); rli.close(); + + // Punctuation runs separated by whitespace: delete-word-right must remove + // exactly the span that word-right traverses. Regression for a `\W+` class + // that also consumed the whitespace and the following punctuation run. + [rli, fi] = getInterface({ terminal: true, prompt: '' }); + fi.emit('data', '-> => x'); + fi.emit('keypress', '.', { ctrl: true, name: 'a' }); + rli.on('line', common.mustCall((line) => { + assert.strictEqual(line, '=> x'); + })); + fi.emit('keypress', '.', deleteWordRightKey); + fi.emit('data', '\n'); + rli.close(); }); // deleteLeft diff --git a/test/parallel/test-readline-promises-interface.js b/test/parallel/test-readline-promises-interface.js index 260431dd69cb..8c8218071ddd 100644 --- a/test/parallel/test-readline-promises-interface.js +++ b/test/parallel/test-readline-promises-interface.js @@ -570,6 +570,19 @@ function assertCursorRowsAndCols(rli, rows, cols) { fi.emit('keypress', '.', deleteWordRightKey); fi.emit('data', '\n'); rli.close(); + + // Punctuation runs separated by whitespace: delete-word-right must remove + // exactly the span that word-right traverses. Regression for a `\W+` class + // that also consumed the whitespace and the following punctuation run. + [rli, fi] = getInterface({ terminal: true, prompt: '' }); + fi.emit('data', '-> => x'); + fi.emit('keypress', '.', { ctrl: true, name: 'a' }); + rli.on('line', common.mustCall((line) => { + assert.strictEqual(line, '=> x'); + })); + fi.emit('keypress', '.', deleteWordRightKey); + fi.emit('data', '\n'); + rli.close(); }); // deleteLeft