diff --git a/src/xterm.js b/src/xterm.js index ce0a246c..273fdca5 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -554,6 +554,7 @@ * 1. stripping all trailing white spaces * 2. converting all non-breaking spaces to regular spaces * @param {string} text The copied text that needs processing for storing in clipboard + * @returns {string} * @static */ Terminal.prepareCopiedTextForClipboard = function (text) { diff --git a/test/test.js b/test/test.js index e603d65f..ffbc285f 100644 --- a/test/test.js +++ b/test/test.js @@ -54,4 +54,18 @@ describe('xterm.js', function() { assert.equal(xterm.evaluateKeyEscapeSequence({ ctrlKey: true, keyCode: 39 }).key, '\x1b[5C'); // CSI 5 C }); }); + + describe('evaluateCopiedTextProcessing', function () { + it('should strip trailing whitespaces and replace nbsps with spaces', function () { + var nonBreakingSpace = String.fromCharCode(160), + copiedText = 'echo' + nonBreakingSpace + 'hello' + nonBreakingSpace, + processedText = Terminal.prepareCopiedTextForClipboard(copiedText); + + // No trailing spaces + assert.equal(processedText.match(/\s+$/), null); + + // No non-breaking space + assert.equal(processedText.indexOf(nonBreakingSpace), -1); + }); + }); });