Skip to content

type: string format: regex does not fail on invalid regular expressions #775

@thomasborgen

Description

@thomasborgen

Hi, I'd like to validate regular expression strings, but it does not seem to give me an error on for example missing closing brackets etc.

tested with python 3.8.2, josnschema 3.2

from jsonschema import Draft7Validator

schema = {
    '$schema': 'http://json-schema.org/draft-07/schema#',
    '$id': 'testid',
    'title': 'regex test schema',
    '$ref': '#/definitions/regexp',
    'definitions': {
        'regexp': {
            'description': 'Regex search string',
            'type': 'object',
            'properties': {
                'search': {
                    'type': 'string',
                    'format': 'regex',
                },
            },
            'required': ['search'],
        },
    },
}


validator = Draft7Validator(schema)

print(validator.check_schema(schema))

print(validator.is_valid({'search': 'test'}))
# True
print(validator.is_valid({'search': '[0-9'}))
# True, but i expect False because of missing bracket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions