Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use JsonSchema\Constraints\ConstraintInterface;
use JsonSchema\Entity\ErrorBagProxy;
use JsonSchema\Entity\JsonPointer;
use JsonSchema\Tool\EcmaPatternConverter;

class UnevaluatedPropertiesConstraint implements ConstraintInterface
{
Expand Down Expand Up @@ -104,7 +105,7 @@ private function collectEvaluatedProperties(object $schema, object $value, ?Json
if (isset($schema->patternProperties) && is_object($schema->patternProperties)) {
foreach ($properties as $propertyName => $_) {
foreach (array_keys(get_object_vars($schema->patternProperties)) as $pattern) {
if (preg_match($this->createPregMatchPattern($pattern), (string) $propertyName)) {
if (preg_match(EcmaPatternConverter::toPcre($pattern), (string) $propertyName)) {
$evaluated[] = $propertyName;
break;
}
Expand Down Expand Up @@ -210,12 +211,4 @@ private function propertyPath(?JsonPointer $path, string $propertyName): JsonPoi

return $basePath->withPropertyPaths(array_merge($basePath->getPropertyPaths(), [$propertyName]));
}

private function createPregMatchPattern(string $pattern): string
{
$pattern = str_replace('\\p{digit}', '\\p{Nd}', $pattern);
$pattern = str_replace('\\p{Letter}', '\\p{L}', $pattern);

return '/' . str_replace('/', '\\/', $pattern) . '/u';
}
}
24 changes: 24 additions & 0 deletions tests/Constraints/Draft2019/EcmaPatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ public static function provideNonAsciiCases(): array
'{"foo-bar": "ok"}',
true,
],
'Arabic-Indic digit does not match \\d in patternProperties with unevaluatedProperties' => [
<<<'JSON'
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"patternProperties": {"^\\d+$": {"type": "string"}},
"unevaluatedProperties": false
}
JSON
,
'{"٣": "ok"}',
false,
],
'ASCII digit matches \\d in patternProperties with unevaluatedProperties' => [
<<<'JSON'
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"patternProperties": {"^\\d+$": {"type": "string"}},
"unevaluatedProperties": false
}
JSON
,
'{"5": "ok"}',
true,
],
];
}
}
Loading