diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index bdd9ccc6d5..e4314330f0 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -469,4 +469,11 @@ describe('InputHandler', () => { } expect(s).equals('World '); }); + describe('print', () => { + it('should not cause an infinite loop (regression test)', () => { + const term = new Terminal(); + const inputHandler = new InputHandler(term); + inputHandler.print(String.fromCharCode(0x200B), 0, 1); + }); + }); }); diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 400e9b9302..ddb20527b5 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -452,8 +452,10 @@ export class InputHandler extends Disposable implements IInputHandler { // fullwidth char - also set next cell to placeholder stub and advance cursor // for graphemes bigger than fullwidth we can simply loop to zero // we already made sure above, that buffer.x + chWidth will not overflow right - while (--chWidth) { - bufferRow.set(buffer.x++, [curAttr, '', 0, undefined]); + if (chWidth > 0) { + while (--chWidth) { + bufferRow.set(buffer.x++, [curAttr, '', 0, undefined]); + } } } this._terminal.updateRange(buffer.y);