Skip to content

Commit 0abe4ec

Browse files
committed
add basic support for unicode blocknames
1 parent b76f9ae commit 0abe4ec

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
@@ -136,8 +136,17 @@ private function loadValidatorType(array &$property, Type $type, $arrayized = fa
136136
break;
137137
case 'pattern':
138138
foreach ($check as $item) {
139+
// initial support for https://www.w3.org/TR/xsd-unicode-blocknames/
140+
// not supported by standard php regex implementation
141+
$regexPattern = strtr($item['value'], [
142+
'\p{IsBasicLatin}' => '\x00-\x7F',
143+
'\p{IsIsBasicLatin}' => '\x{0000}-\x{007F}',
144+
'\p{IsLatin-1Supplement}' => '\x{0080}-\x{00FF}',
145+
'\p{IsLatinExtended-A}' => '\x{0100}-\x{024F}',
146+
'\p{IsLatinExtended-B}' => '\x{0180}-\x{024F}',
147+
]);
139148
$rules[] = [
140-
'Regex' => ['pattern' => "~{$item['value']}~"],
149+
'Regex' => ['pattern' => "~{$regexPattern}~"],
141150
];
142151
}
143152
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)