From 65d1260183d8ab653e7f814d20d723f4a5ce38ca Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 4 Nov 2024 18:32:35 +0900 Subject: [PATCH] mbstring: Fix mb_rtrim() for UTF-8 text --- src/Mbstring/Mbstring.php | 2 +- tests/Mbstring/MbstringTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Mbstring/Mbstring.php b/src/Mbstring/Mbstring.php index 3d45c9d9a..31e36a368 100644 --- a/src/Mbstring/Mbstring.php +++ b/src/Mbstring/Mbstring.php @@ -983,7 +983,7 @@ public static function mb_ltrim(string $string, ?string $characters = null, ?str public static function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { - return self::mb_internal_trim('{[%s]+$}D', $string, $characters, $encoding, __FUNCTION__); + return self::mb_internal_trim('{[%s]+$}Du', $string, $characters, $encoding, __FUNCTION__); } private static function mb_internal_trim(string $regex, string $string, ?string $characters, ?string $encoding, string $function): string diff --git a/tests/Mbstring/MbstringTest.php b/tests/Mbstring/MbstringTest.php index 2020f4566..49a9aff10 100644 --- a/tests/Mbstring/MbstringTest.php +++ b/tests/Mbstring/MbstringTest.php @@ -886,6 +886,7 @@ public static function mbLTrimProvider(): iterable yield [' test ', ' test ', '']; yield ['いああああ', 'あああああああああああああああああああああああああああああああああいああああ', 'あ']; + yield ['あいうえお ', ' あいうえお ']; yield ['漢字', "\u{FFFE}漢字", "\u{FFFE}\u{FEFF}"]; yield [' abcd ', ' abcd ', '']; @@ -902,6 +903,7 @@ public static function mbRTrimProvider(): iterable yield [' a', str_repeat(' ', 129).'a']; yield ['あああああああああああああああああああああああああああああああああい', 'あああああああああああああああああああああああああああああああああいああああ', 'あ']; + yield [' あいうえお', ' あいうえお ']; yield [' abcd ', ' abcd ', ''];