mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Add validation for boolean values, affects #128429
This commit is contained in:
parent
6a6c1195b8
commit
56d3a7da35
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in a new issue