From 0abe4ecac7e2fd81bbb891053ed28abe6f7efefa Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 30 Aug 2023 10:39:05 +0200 Subject: [PATCH] add basic support for unicode blocknames --- src/Jms/YamlValidatorConverter.php | 11 ++++++++++- tests/Converter/Validator/Xsd2ValidatorTest.php | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Jms/YamlValidatorConverter.php b/src/Jms/YamlValidatorConverter.php index bc4cd4ff..50a38062 100644 --- a/src/Jms/YamlValidatorConverter.php +++ b/src/Jms/YamlValidatorConverter.php @@ -136,8 +136,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; diff --git a/tests/Converter/Validator/Xsd2ValidatorTest.php b/tests/Converter/Validator/Xsd2ValidatorTest.php index f6e6805f..5b187543 100644 --- a/tests/Converter/Validator/Xsd2ValidatorTest.php +++ b/tests/Converter/Validator/Xsd2ValidatorTest.php @@ -125,6 +125,17 @@ public function getRestrictionsValidations() ], ], // pattern / Regex + [ + '', + [ + [ + 'Regex' => [ + 'pattern' => '~[\\x00-\\x7F\\x{0080}-\\x{00FF}]+~', + 'groups' => ['xsd_rules'], + ], + ], + ], + ], [ '', [