Skip to content

Commit

Permalink
Fix bug #79787
Browse files Browse the repository at this point in the history
Closes GH-5807.
  • Loading branch information
x-xiang authored and nikic committed Jul 8, 2020
1 parent e6160e9 commit 3d5de7d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ PHP NEWS
- FTP:
. Fixed bug #55857 (ftp_size on large files). (cmb)

- Mbstring:
. Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang)

- Standard:
. Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb)

Expand Down
14 changes: 9 additions & 5 deletions ext/mbstring/libmbfl/mbfl/mbfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1734,13 +1734,17 @@ mbfl_strimwidth(
mbfl_convert_filter_flush(encoder);
if (pc.status != 0 && mkwidth > 0) {
pc.width += mkwidth;
while (n > 0) {
if ((*encoder->filter_function)(*p++, encoder) < 0) {
break;
if (n > 0) {
while (n > 0) {
if ((*encoder->filter_function)(*p++, encoder) < 0) {
break;
}
n--;
}
n--;
mbfl_convert_filter_flush(encoder);
} else if (pc.outwidth > pc.width) {
pc.status++;
}
mbfl_convert_filter_flush(encoder);
if (pc.status != 1) {
pc.status = 10;
pc.device.pos = pc.endpos;
Expand Down
20 changes: 20 additions & 0 deletions ext/mbstring/tests/bug79787.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #79787 mb_strimwidth does not trim string
--SKIPIF--
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--FILE--
<?php
echo mb_strimwidth("一二三", 0, 4, '.', 'UTF-8')."\n";
echo mb_strimwidth("一二三", 0, 5, '.', 'UTF-8')."\n";
echo mb_strimwidth("一二三", 0, 6, '.', 'UTF-8')."\n";
echo mb_strimwidth("abcdef", 0, 4, '.', 'UTF-8')."\n";
echo mb_strimwidth("abcdef", 0, 5, '.', 'UTF-8')."\n";
echo mb_strimwidth("abcdef", 0, 6, '.', 'UTF-8')."\n";
?>
--EXPECT--
一.
一二.
一二三
abc.
abcd.
abcdef

0 comments on commit 3d5de7d

Please sign in to comment.