tdegrunt/jsonschema

"patternProperties" regex not validating properly

XeniaSiskaki opened this issue · 1 comments

I'm using the patterProperties to validate some keys but it's not validating as expected. It seems to successfully validate all keys even if they are invalid.

I have the following snippet to reproduce the issue:

const schema = {
    type: 'object',
    patternProperties: {
        '^[a-zA-Z](\\w*[a-zA-Z0-9])?$': {
            type: 'array',
            items: { type: 'string' }
        }
    },
    additionalProperties: false
};
// prints empty string
console.log(validate({ '1e_2ds': ['a'] }, schema).errors.toString());

According to the patternProperties regex the string shouldn't be allowed to start with a numeric.

regex101 seems to also agree
Screenshot from 2020-11-20 10-48-28

Seems like I messed up the schema, closing for now