Add validation for boolean values, affects #128429

This commit is contained in:
Raymond Zhao 2021-07-26 12:13:23 -07:00
parent 6a6c1195b8
commit 56d3a7da35
No known key found for this signature in database
GPG key ID: D36E5FCE46B63B58
2 changed files with 15 additions and 1 deletions

View file

@ -47,6 +47,10 @@ export function createValidator(prop: IConfigurationPropertySchema): (value: any
}
}
if (prop.type === 'boolean' && value !== true && value !== false) {
errors.push(nls.localize('validations.booleanIncorrectType', 'Incorrect type. Expected "boolean".'));
}
if (isNumeric) {
if (isNullOrEmpty(value) || isNaN(+value)) {
errors.push(nls.localize('validations.expectedNumeric', "Value must be a number."));
@ -57,7 +61,7 @@ export function createValidator(prop: IConfigurationPropertySchema): (value: any
if (prop.type === 'string') {
if (!isString(value)) {
errors.push(nls.localize('validations.incorrectType', 'Incorrect type. Expected "string".'));
errors.push(nls.localize('validations.stringIncorrectType', 'Incorrect type. Expected "string".'));
} else {
errors.push(...stringValidations.filter(validator => !validator.isValid(value)).map(validator => validator.message));
}

View file

@ -267,6 +267,16 @@ suite('Preferences Validation', () => {
pattern.rejects({ '#ab': 99999 });
pattern.accepts({});
}
{
const pattern = new Tester({ type: 'object', properties: { 'hello': { type: 'string' } }, additionalProperties: { type: 'boolean' } });
pattern.accepts({ 'hello': 'world' });
pattern.accepts({ 'hello': 'world', 'bye': false });
pattern.rejects({ 'hello': 'world', 'bye': 'false' });
pattern.rejects({ 'hello': 'world', 'bye': 1 });
pattern.rejects({ 'hello': 'world', 'bye': 'world' });
pattern.accepts({ 'hello': 'test' });
pattern.accepts({});
}
});
test('patterns work', () => {