Skip to content

Commit 77a8a70

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #79787
2 parents 776e872 + 3d5de7d commit 77a8a70

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
@@ -32,6 +32,9 @@ PHP NEWS
3232
- FTP:
3333
. Fixed bug #55857 (ftp_size on large files). (cmb)
3434

35+
- Mbstring:
36+
. Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang)
37+
3538
- Reflection:
3639
. Fixed bug #79487 (::getStaticProperties() ignores property modifications).
3740
(cmb, Nikita)

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,13 +1724,17 @@ mbfl_strimwidth(
17241724
mbfl_convert_filter_flush(encoder);
17251725
if (pc.status != 0 && mkwidth > 0) {
17261726
pc.width += mkwidth;
1727-
while (n > 0) {
1728-
if ((*encoder->filter_function)(*p++, encoder) < 0) {
1729-
break;
1727+
if (n > 0) {
1728+
while (n > 0) {
1729+
if ((*encoder->filter_function)(*p++, encoder) < 0) {
1730+
break;
1731+
}
1732+
n--;
17301733
}
1731-
n--;
1734+
mbfl_convert_filter_flush(encoder);
1735+
} else if (pc.outwidth > pc.width) {
1736+
pc.status++;
17321737
}
1733-
mbfl_convert_filter_flush(encoder);
17341738
if (pc.status != 1) {
17351739
pc.status = 10;
17361740
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)