From 082774a509349c7d908452d3a334ef8e075c33ff Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 27 Jul 2023 12:25:08 +0300 Subject: [PATCH 1/2] Fix incorrect split UTF-8 strings --- CHANGELOG.md | 2 +- src/StringHelper.php | 2 +- tests/StringHelperTest.php | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 671e77b..ee53da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.1.2 under development -- no changes in this release. +- Bug #105: Fix incorrect split UTF-8 strings in some cases in `StringHelper::split()` method (@vjik) ## 2.1.1 April 28, 2023 diff --git a/src/StringHelper.php b/src/StringHelper.php index 46681ad..6f297ee 100644 --- a/src/StringHelper.php +++ b/src/StringHelper.php @@ -496,7 +496,7 @@ public static function base64UrlDecode(string $input): string public static function split(string $string, string $separator = '\R'): array { $string = preg_replace('(^\s*|\s*$)', '', $string); - return preg_split('~\s*' . $separator . '\s*~', $string, -1, PREG_SPLIT_NO_EMPTY); + return preg_split('~\s*' . $separator . '\s*~u', $string, -1, PREG_SPLIT_NO_EMPTY); } /** diff --git a/tests/StringHelperTest.php b/tests/StringHelperTest.php index a2b15da..4f16c46 100644 --- a/tests/StringHelperTest.php +++ b/tests/StringHelperTest.php @@ -407,6 +407,10 @@ public function dataSplit(): array "\0\nA\nB", ["\0", 'A', 'B'], ], + [ + "технический\nдолг", + ['технический', 'долг'], + ], ]; } From eb403aae26629e23299095e16bac5457386c8f21 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 27 Jul 2023 12:26:30 +0300 Subject: [PATCH 2/2] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee53da5..15b0c84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.1.2 under development -- Bug #105: Fix incorrect split UTF-8 strings in some cases in `StringHelper::split()` method (@vjik) +- Bug #105: Fix incorrect split UTF-8 strings in `StringHelper::split()` method (@vjik) ## 2.1.1 April 28, 2023