Skip to content
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

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

Open
claudiofreitas opened this issue Aug 7, 2018 · 2 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!

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

2 participants