tdegrunt / jsonschema

JSON Schema validation
Other
1.83k stars 263 forks source link

"patternProperties" regex not validating properly #328

Closed XeniaSiskaki closed 4 years ago

XeniaSiskaki commented 4 years ago

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

XeniaSiskaki commented 4 years ago

Seems like I messed up the schema, closing for now