Skip to content

Commit 10d1f69

Browse files
jbaron-gingcobighappyface
authored andcommitted
[BUGFIX] Use unicode matching for patterns, since JSON allows all unicode. (#330)
1 parent 52b77d7 commit 10d1f69

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/JsonSchema/Constraints/StringConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function check($element, $schema = null, JsonPointer $path = null, $i = n
3939
}
4040

4141
// Verify a regex pattern
42-
if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#', $element)) {
42+
if (isset($schema->pattern) && !preg_match('#' . str_replace('#', '\\#', $schema->pattern) . '#u', $element)) {
4343
$this->addError($path, "Does not match the regex pattern " . $schema->pattern, 'pattern', array(
4444
'pattern' => $schema->pattern,
4545
));

tests/Constraints/PatternTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ public function getInvalidTests()
3535
},
3636
"additionalProperties": false
3737
}'
38-
)
38+
),
39+
array(
40+
'{"value": "ü"}',
41+
'{
42+
"type": "object",
43+
"properties": {
44+
"value": {"type": "string", "pattern": "^ü$"}
45+
},
46+
"additionalProperties": false
47+
}'
48+
),
3949
);
4050
}
4151

@@ -75,6 +85,16 @@ public function getValidTests()
7585
},
7686
"additionalProperties": false
7787
}'
88+
),
89+
array(
90+
'{"value": "↓æ→"}',
91+
'{
92+
"type": "object",
93+
"properties": {
94+
"value": {"type": "string", "pattern": "^↓æ.$"}
95+
},
96+
"additionalProperties": false
97+
}'
7898
)
7999
);
80100
}

0 commit comments

Comments
 (0)