Skip to content

Commit 0e71446

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix bug #79787
2 parents fa5355b + 77a8a70 commit 0e71446

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,13 +1617,17 @@ mbfl_strimwidth(
16171617
mbfl_convert_filter_flush(encoder);
16181618
if (pc.status != 0 && mkwidth > 0) {
16191619
pc.width += mkwidth;
1620-
while (n > 0) {
1621-
if ((*encoder->filter_function)(*p++, encoder) < 0) {
1622-
break;
1620+
if (n > 0) {
1621+
while (n > 0) {
1622+
if ((*encoder->filter_function)(*p++, encoder) < 0) {
1623+
break;
1624+
}
1625+
n--;
16231626
}
1624-
n--;
1627+
mbfl_convert_filter_flush(encoder);
1628+
} else if (pc.outwidth > pc.width) {
1629+
pc.status++;
16251630
}
1626-
mbfl_convert_filter_flush(encoder);
16271631
if (pc.status != 1) {
16281632
pc.status = 10;
16291633
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)