json-schema
json-schema copied to clipboard
ErrorException: StringConstraint.php:42 -- preg_match(): Unknown modifier 'r'
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?
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.
@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!