Merge pull request #3064 from IllusionMH/validate-constructor-options-3063

Validate constructor options
This commit is contained in:
Daniel Imms
2020-09-02 08:36:04 -07:00
committed by GitHub
2 changed files with 28 additions and 2 deletions
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2020 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { assert } from 'chai';
import { OptionsService, DEFAULT_OPTIONS } from 'common/services/OptionsService';
describe('OptionsService', () => {
describe('constructor', () => {
const originalError = console.error;
beforeEach(() => {
console.error = () => {};
});
afterEach(() => {
console.error = originalError;
});
it('uses default value if invalid constructor option value passed', () => {
assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
});
});
});
+6 -2
View File
@@ -73,8 +73,12 @@ export class OptionsService implements IOptionsService {
this.options = clone(DEFAULT_OPTIONS);
for (const k of Object.keys(options)) {
if (k in this.options) {
const newValue = options[k as keyof IPartialTerminalOptions] as any;
this.options[k] = newValue;
try {
const newValue = options[k as keyof IPartialTerminalOptions] as any;
this.options[k] = this._sanitizeAndValidateOption(k, newValue);
} catch (e) {
console.error(e);
}
}
}
}