php-json-schema icon indicating copy to clipboard operation
php-json-schema copied to clipboard

Patterns don't use /

Open fidian opened this issue 11 years ago • 3 comments

According to the examples I've seen on mailing lists, JSON Schema's patterns look like this:

{
    "type": "string",
    "pattern": "^[a-zA-Z]*$"
}

Your tests assume they start and end with a slash.

fidian avatar Nov 08 '12 02:11 fidian

Is there any update on this pull request? I see that the other JSON schema project asked you to join their forces (and that's awesome), but I'd still love for this library to get this bug fixed.

fidian avatar Dec 20 '12 20:12 fidian

+1 on the need

Even if there is a good solution to this problem, I don't know the odds of it getting merged in after 9 months. I'll try to stay hopeful though.

Still hopeful after 2 years 3 months?

bmoelk avatar Oct 23 '15 16:10 bmoelk

Backticks don't have any special meaning within the regex AND can be used as delimiters (if escaped), therefore I believe this code should work:

if (!preg_match('' . str_replace('', '', $schema->pattern) . '', $entity)) {

Forked/fixed/tested here: https://github.com/shrm-org/php-json-schema

bmoelk avatar Oct 23 '15 17:10 bmoelk