Skip to content

Commit 505fef8

Browse files
authored
Merge pull request #159 from goetas-webservices/regex-unicode-props
Add basic support for unicode blocknames
2 parents ac0e34a + 0abe4ec commit 505fef8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Jms/YamlValidatorConverter.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,17 @@ private function loadValidatorType(array &$property, Type $type, $arrayized = fa
143143
break;
144144
case 'pattern':
145145
foreach ($check as $item) {
146+
// initial support for https://www.w3.org/TR/xsd-unicode-blocknames/
147+
// not supported by standard php regex implementation
148+
$regexPattern = strtr($item['value'], [
149+
'\p{IsBasicLatin}' => '\x00-\x7F',
150+
'\p{IsIsBasicLatin}' => '\x{0000}-\x{007F}',
151+
'\p{IsLatin-1Supplement}' => '\x{0080}-\x{00FF}',
152+
'\p{IsLatinExtended-A}' => '\x{0100}-\x{024F}',
153+
'\p{IsLatinExtended-B}' => '\x{0180}-\x{024F}',
154+
]);
146155
$rules[] = [
147-
'Regex' => ['pattern' => "~{$item['value']}~"],
156+
'Regex' => ['pattern' => "~{$regexPattern}~"],
148157
];
149158
}
150159
break;

tests/Converter/Validator/Xsd2ValidatorTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public function getRestrictionsValidations()
125125
],
126126
],
127127
// pattern / Regex
128+
[
129+
'<xs:pattern value="[\\p{IsBasicLatin}\\p{IsLatin-1Supplement}]+"/>',
130+
[
131+
[
132+
'Regex' => [
133+
'pattern' => '~[\\x00-\\x7F\\x{0080}-\\x{00FF}]+~',
134+
'groups' => ['xsd_rules'],
135+
],
136+
],
137+
],
138+
],
128139
[
129140
'<xs:pattern value="\\([0-9]{2}\\)\\s[0-9]{4}-[0-9]{4,5}"/>',
130141
[

0 commit comments

Comments
 (0)