diff --git a/src/JsonSchema/Constraints/StringConstraint.php b/src/JsonSchema/Constraints/StringConstraint.php index 44313cb2..724a8103 100644 --- a/src/JsonSchema/Constraints/StringConstraint.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -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, )); diff --git a/tests/Constraints/PatternTest.php b/tests/Constraints/PatternTest.php index f28a5790..0f69b9ad 100644 --- a/tests/Constraints/PatternTest.php +++ b/tests/Constraints/PatternTest.php @@ -35,7 +35,17 @@ public function getInvalidTests() }, "additionalProperties": false }' - ) + ), + array( + '{"value": "ü"}', + '{ + "type": "object", + "properties": { + "value": {"type": "string", "pattern": "^ü$"} + }, + "additionalProperties": false + }' + ), ); } @@ -75,6 +85,16 @@ public function getValidTests() }, "additionalProperties": false }' + ), + array( + '{"value": "↓æ→"}', + '{ + "type": "object", + "properties": { + "value": {"type": "string", "pattern": "^↓æ.$"} + }, + "additionalProperties": false + }' ) ); }