Skip to content

ErrorException: StringConstraint.php:42 -- preg_match(): Unknown modifier 'r' #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
claudiofreitas opened this issue Aug 7, 2018 · 3 comments

Comments

@claudiofreitas
Copy link

Hello,

I have a schema.json like below, and when I try to validate my json (also below) I'm receiving the Exception from the title.

schema.json:

{
    "$schema": "http://json-schema.org/schema#",
    "type": "string",
    "pattern": "^\\#ref\\(.+\\)$"
}

json:

"ref"

Investigating the StringConstraint.php, on line 42 it has this code:

if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u', $element)) {

which is replacing # by \\# and concatenating everything with #-prefix and #u-suffix.

Am I going something wrong or is it a bug?

@erayd
Copy link
Contributor

erayd commented Aug 7, 2018

Yes, this is a bug.

The logic is supposed to replace # with \#, and then wrap with #<pattern>#u (i.e. #-delimited pattern with the unicode modifier). This behavior is deliberate, but the bug is that it seems to be still interpreting the # from your pattern as a delimiter, rather than an escaped literal.

@claudiofreitas
Copy link
Author

@erayd I see.
If I have some time, I will try to investigate further and see if I can come with some fix and PR it.

Thank you very much!

@DannyvdSluijs
Copy link
Collaborator

@claudiofreitas this was indeed a bug. However over time the bug got resolved and we've taken more time to get back to this report.

With the changes made in #653 this issue was resolved. I've checked your schema and JSON which doesn't validate because the JSON value doesn't match the regular expression. Using "#ref(something)" as JSON the validation succeeds.
The fix is included in 6.0.0 and above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants