Skip to content

Commit

Permalink
Merge pull request #159 from goetas-webservices/regex-unicode-props
Browse files Browse the repository at this point in the history
Add basic support for unicode blocknames
  • Loading branch information
goetas authored Aug 30, 2023
2 parents ac0e34a + 0abe4ec commit 505fef8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Jms/YamlValidatorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,17 @@ private function loadValidatorType(array &$property, Type $type, $arrayized = fa
break;
case 'pattern':
foreach ($check as $item) {
// initial support for https://www.w3.org/TR/xsd-unicode-blocknames/
// not supported by standard php regex implementation
$regexPattern = strtr($item['value'], [
'\p{IsBasicLatin}' => '\x00-\x7F',
'\p{IsIsBasicLatin}' => '\x{0000}-\x{007F}',
'\p{IsLatin-1Supplement}' => '\x{0080}-\x{00FF}',
'\p{IsLatinExtended-A}' => '\x{0100}-\x{024F}',
'\p{IsLatinExtended-B}' => '\x{0180}-\x{024F}',
]);
$rules[] = [
'Regex' => ['pattern' => "~{$item['value']}~"],
'Regex' => ['pattern' => "~{$regexPattern}~"],
];
}
break;
Expand Down
11 changes: 11 additions & 0 deletions tests/Converter/Validator/Xsd2ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public function getRestrictionsValidations()
],
],
// pattern / Regex
[
'<xs:pattern value="[\\p{IsBasicLatin}\\p{IsLatin-1Supplement}]+"/>',
[
[
'Regex' => [
'pattern' => '~[\\x00-\\x7F\\x{0080}-\\x{00FF}]+~',
'groups' => ['xsd_rules'],
],
],
],
],
[
'<xs:pattern value="\\([0-9]{2}\\)\\s[0-9]{4}-[0-9]{4,5}"/>',
[
Expand Down

0 comments on commit 505fef8

Please sign in to comment.