From d2468687606ff67caf047ad4f3e90def2ad2f8aa Mon Sep 17 00:00:00 2001 From: galiaf1987 <40261486+galiaf1987@users.noreply.github.com> Date: Tue, 28 Sep 2021 20:58:44 +0500 Subject: [PATCH] Add unicode (#142) * Add unicode * Fix * Update PatternTest --- src/Schema/Keywords/Pattern.php | 2 +- tests/Schema/Keywords/PatternTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Schema/Keywords/Pattern.php b/src/Schema/Keywords/Pattern.php index ccf91655..be405cc2 100644 --- a/src/Schema/Keywords/Pattern.php +++ b/src/Schema/Keywords/Pattern.php @@ -38,7 +38,7 @@ public function validate($data, string $pattern): void throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e); } - $pattern = sprintf('#%s#', str_replace('#', '\#', $pattern)); + $pattern = sprintf('#%s#u', str_replace('#', '\#', $pattern)); if (! preg_match($pattern, $data)) { throw KeywordMismatch::fromKeyword('pattern', $data, sprintf('Data does not match pattern \'%s\'', $pattern)); diff --git a/tests/Schema/Keywords/PatternTest.php b/tests/Schema/Keywords/PatternTest.php index 2a33bdca..3079a44e 100644 --- a/tests/Schema/Keywords/PatternTest.php +++ b/tests/Schema/Keywords/PatternTest.php @@ -22,6 +22,7 @@ public function validDataProvider(): array ['1foo1', '1foo1'], // Tests adding anchors when first and last character is same with numbers ['^#\d+$', '#123'], // Tests adding anchors to string which has # ['^#(\d+)#$', '#123#'], // Tests adding anchors to string which has multiple# + ['^[А-Я]{2}$', 'ДГ'], // Tests patterns with Unicode ]; }