Add validation for boolean values, affects #128429
This commit is contained in:
parent
6a6c1195b8
commit
56d3a7da35
2 changed files with 15 additions and 1 deletions
|
@ -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 (isNumeric) {
|
||||||
if (isNullOrEmpty(value) || isNaN(+value)) {
|
if (isNullOrEmpty(value) || isNaN(+value)) {
|
||||||
errors.push(nls.localize('validations.expectedNumeric', "Value must be a number."));
|
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 (prop.type === 'string') {
|
||||||
if (!isString(value)) {
|
if (!isString(value)) {
|
||||||
errors.push(nls.localize('validations.incorrectType', 'Incorrect type. Expected "string".'));
|
errors.push(nls.localize('validations.stringIncorrectType', 'Incorrect type. Expected "string".'));
|
||||||
} else {
|
} else {
|
||||||
errors.push(...stringValidations.filter(validator => !validator.isValid(value)).map(validator => validator.message));
|
errors.push(...stringValidations.filter(validator => !validator.isValid(value)).map(validator => validator.message));
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,6 +267,16 @@ suite('Preferences Validation', () => {
|
||||||
pattern.rejects({ '#ab': 99999 });
|
pattern.rejects({ '#ab': 99999 });
|
||||||
pattern.accepts({});
|
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', () => {
|
test('patterns work', () => {
|
||||||
|
|
Loading…
Reference in a new issue