Skip to content

Commit b5df612

Browse files
authored
Merge pull request #3453 from silamon/undefinedrowscols
Passing cols or rows into ctor as undefined will break terminal
2 parents b9b42ef + fa77825 commit b5df612

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/common/services/BufferService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export class BufferService extends Disposable implements IBufferService {
3636
@IOptionsService private _optionsService: IOptionsService
3737
) {
3838
super();
39-
this.cols = Math.max(_optionsService.options.cols, MINIMUM_COLS);
40-
this.rows = Math.max(_optionsService.options.rows, MINIMUM_ROWS);
39+
this.cols = Math.max(_optionsService.options.cols || 0, MINIMUM_COLS);
40+
this.rows = Math.max(_optionsService.options.rows || 0, MINIMUM_ROWS);
4141
this.buffers = new BufferSet(_optionsService, this);
4242
}
4343

src/common/services/OptionsService.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ describe('OptionsService', () => {
1515
afterEach(() => {
1616
console.error = originalError;
1717
});
18+
it('uses default value if invalid constructor option values passed for cols/rows', () => {
19+
const optionsService = new OptionsService({ cols: undefined, rows: undefined });
20+
assert.equal(optionsService.getOption('rows'), DEFAULT_OPTIONS.rows);
21+
assert.equal(optionsService.getOption('cols'), DEFAULT_OPTIONS.cols);
22+
});
23+
it('uses values from constructor option values if correctly passed', () => {
24+
const optionsService = new OptionsService({ cols: 80, rows: 25 });
25+
assert.equal(optionsService.getOption('rows'), 25);
26+
assert.equal(optionsService.getOption('cols'), 80);
27+
});
1828
it('uses default value if invalid constructor option value passed', () => {
1929
assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
2030
});

src/common/services/OptionsService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ export class OptionsService implements IOptionsService {
149149
if (value <= 0) {
150150
throw new Error(`${key} cannot be less than or equal to 0, value: ${value}`);
151151
}
152+
case 'rows':
153+
case 'cols':
154+
if (!value && value !== 0) {
155+
throw new Error(`${key} must be numeric, value: ${value}`);
156+
}
152157
break;
153158
}
154159
return value;

0 commit comments

Comments
 (0)