java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.62k stars 399 forks source link

Schema validator dont check regular expression #243

Open sginer opened 6 years ago

sginer commented 6 years ago

Property with regexp pattern dosn not work fine. For example, this schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "id": {
            "type": "string",
            "pattern": "[A-Za-z0-9\\-\\.]{1,64}"
        }
    }
}

validate this invalid json

{
    "id" : "re@"
}

but dont validate this

{
    "id" : "@"
}
blag001 commented 6 years ago

Not a bug. Your REGEX is not what you think:

https://regex101.com/r/KcJKh9/1

You're after a ^[A-Za-z0-9.-]{1,64}$: https://regex101.com/r/APgsZP/2

Regards, Blag