mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge pull request #3453 from silamon/undefinedrowscols
Passing cols or rows into ctor as undefined will break terminal
This commit is contained in:
@@ -36,8 +36,8 @@ export class BufferService extends Disposable implements IBufferService {
|
||||
@IOptionsService private _optionsService: IOptionsService
|
||||
) {
|
||||
super();
|
||||
this.cols = Math.max(_optionsService.options.cols, MINIMUM_COLS);
|
||||
this.rows = Math.max(_optionsService.options.rows, MINIMUM_ROWS);
|
||||
this.cols = Math.max(_optionsService.options.cols || 0, MINIMUM_COLS);
|
||||
this.rows = Math.max(_optionsService.options.rows || 0, MINIMUM_ROWS);
|
||||
this.buffers = new BufferSet(_optionsService, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,16 @@ describe('OptionsService', () => {
|
||||
afterEach(() => {
|
||||
console.error = originalError;
|
||||
});
|
||||
it('uses default value if invalid constructor option values passed for cols/rows', () => {
|
||||
const optionsService = new OptionsService({ cols: undefined, rows: undefined });
|
||||
assert.equal(optionsService.getOption('rows'), DEFAULT_OPTIONS.rows);
|
||||
assert.equal(optionsService.getOption('cols'), DEFAULT_OPTIONS.cols);
|
||||
});
|
||||
it('uses values from constructor option values if correctly passed', () => {
|
||||
const optionsService = new OptionsService({ cols: 80, rows: 25 });
|
||||
assert.equal(optionsService.getOption('rows'), 25);
|
||||
assert.equal(optionsService.getOption('cols'), 80);
|
||||
});
|
||||
it('uses default value if invalid constructor option value passed', () => {
|
||||
assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
|
||||
});
|
||||
|
||||
@@ -149,6 +149,11 @@ export class OptionsService implements IOptionsService {
|
||||
if (value <= 0) {
|
||||
throw new Error(`${key} cannot be less than or equal to 0, value: ${value}`);
|
||||
}
|
||||
case 'rows':
|
||||
case 'cols':
|
||||
if (!value && value !== 0) {
|
||||
throw new Error(`${key} must be numeric, value: ${value}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
|
||||
Reference in New Issue
Block a user