Skip to content

Commit

Permalink
[BUGFIX] Use unicode matching for patterns, since JSON allows all uni…
Browse files Browse the repository at this point in the history
…code. (#330)
  • Loading branch information
jbaron-gingco authored and bighappyface committed Nov 9, 2016
1 parent 52b77d7 commit 10d1f69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/StringConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function check($element, $schema = null, JsonPointer $path = null, $i = n
}

// Verify a regex pattern
if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#', $element)) {
if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u', $element)) {
$this->addError($path, "Does not match the regex pattern " . $schema->pattern, 'pattern', array(
'pattern' => $schema->pattern,
));
Expand Down
22 changes: 21 additions & 1 deletion tests/Constraints/PatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ public function getInvalidTests()
},
"additionalProperties": false
}'
)
),
array(
'{"value": "ü"}',
'{
"type": "object",
"properties": {
"value": {"type": "string", "pattern": "^ü$"}
},
"additionalProperties": false
}'
),
);
}

Expand Down Expand Up @@ -75,6 +85,16 @@ public function getValidTests()
},
"additionalProperties": false
}'
),
array(
'{"value": "↓æ→"}',
'{
"type": "object",
"properties": {
"value": {"type": "string", "pattern": "^↓æ.$"}
},
"additionalProperties": false
}'
)
);
}
Expand Down

0 comments on commit 10d1f69

Please sign in to comment.