Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patternProperies: regexp doesn't work - it should work? #52

Closed
d-adamkiewicz opened this issue Aug 27, 2012 · 1 comment
Closed

patternProperies: regexp doesn't work - it should work? #52

d-adamkiewicz opened this issue Aug 27, 2012 · 1 comment

Comments

@d-adamkiewicz
Copy link

Hi,
I'm not sure if it's bug or I'm doing something wrong

- the following code reports always success. It seems regexp isn't taken into account.

var JSV = require('JSV').JSV;
var env = JSV.createEnvironment();
var json, schema;
var result = env.validate(json = {Z:1}, schema = {type: 'object', patternProperties: {'[a-z]': {type:'number'}}});
console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4));
if (result.errors.length === 0) {
console.log('success');
} else {
console.log('failure');
}
result = env.validate(json = {a:1}, schema = {type: 'object', patternProperties: {'[A-Z]': {type:'number'}}});
console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4));
if (result.errors.length === 0) {
console.log('success');
} else {
console.log('failure');
}
result = env.validate(json = {a:1}, schema = {type: 'object', patternProperties: {'^a\d': {type:'number'}}});
console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4));
if (result.errors.length === 0) {
console.log('success');
} else {
console.log('failure');
}

@garycourt
Copy link
Owner

You need to use "additionalProperties" : false to cause errors to be thrown on undefined properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants