Add validation for boolean values, affects #128429

上级 6a6c1195
......@@ -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));
}
......
......@@ -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', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册