Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mbstring: Fix mb_rtrim() for UTF-8 text #507

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mbstring/Mbstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/Mbstring/MbstringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ public static function mbLTrimProvider(): iterable
yield [' test ', ' test ', ''];

yield ['いああああ', 'あああああああああああああああああああああああああああああああああいああああ', 'あ'];
yield ['あいうえお ', ' あいうえお '];

yield ['漢字', "\u{FFFE}漢字", "\u{FFFE}\u{FEFF}"];
yield [' abcd ', ' abcd ', ''];
Expand All @@ -902,6 +903,7 @@ public static function mbRTrimProvider(): iterable
yield [' a', str_repeat(' ', 129).'a'];

yield ['あああああああああああああああああああああああああああああああああい', 'あああああああああああああああああああああああああああああああああいああああ', 'あ'];
yield [' あいうえお', ' あいうえお '];

yield [' abcd ', ' abcd ', ''];

Expand Down
Loading