Skip to content

Commit 3d5de7d

Browse files
x-xiangnikic
authored andcommitted
Fix bug #79787
Closes GH-5807.
1 parent e6160e9 commit 3d5de7d

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ PHP NEWS
2525
- FTP:
2626
. Fixed bug #55857 (ftp_size on large files). (cmb)
2727

28+
- Mbstring:
29+
. Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang)
30+
2831
- Standard:
2932
. Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb)
3033

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,13 +1734,17 @@ mbfl_strimwidth(
17341734
mbfl_convert_filter_flush(encoder);
17351735
if (pc.status != 0 && mkwidth > 0) {
17361736
pc.width += mkwidth;
1737-
while (n > 0) {
1738-
if ((*encoder->filter_function)(*p++, encoder) < 0) {
1739-
break;
1737+
if (n > 0) {
1738+
while (n > 0) {
1739+
if ((*encoder->filter_function)(*p++, encoder) < 0) {
1740+
break;
1741+
}
1742+
n--;
17401743
}
1741-
n--;
1744+
mbfl_convert_filter_flush(encoder);
1745+
} else if (pc.outwidth > pc.width) {
1746+
pc.status++;
17421747
}
1743-
mbfl_convert_filter_flush(encoder);
17441748
if (pc.status != 1) {
17451749
pc.status = 10;
17461750
pc.device.pos = pc.endpos;

ext/mbstring/tests/bug79787.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #79787 mb_strimwidth does not trim string
3+
--SKIPIF--
4+
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5+
--FILE--
6+
<?php
7+
echo mb_strimwidth("一二三", 0, 4, '.', 'UTF-8')."\n";
8+
echo mb_strimwidth("一二三", 0, 5, '.', 'UTF-8')."\n";
9+
echo mb_strimwidth("一二三", 0, 6, '.', 'UTF-8')."\n";
10+
echo mb_strimwidth("abcdef", 0, 4, '.', 'UTF-8')."\n";
11+
echo mb_strimwidth("abcdef", 0, 5, '.', 'UTF-8')."\n";
12+
echo mb_strimwidth("abcdef", 0, 6, '.', 'UTF-8')."\n";
13+
?>
14+
--EXPECT--
15+
一.
16+
一二.
17+
一二三
18+
abc.
19+
abcd.
20+
abcdef

0 commit comments

Comments
 (0)