summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-07-08 11:21:48 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-07-08 11:22:18 +0200
commit77a8a709dae567d168d9041991f8e8cf17a4654c (patch)
tree77c842e0a8c81414a61a1be44e85e75afd210920
parent776e872ab80097865c737dfbf39d75baf2953168 (diff)
parent3d5de7d74660b1ba6ae92a91581f7a50573554dc (diff)
downloadphp-git-77a8a709dae567d168d9041991f8e8cf17a4654c.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #79787
-rw-r--r--NEWS3
-rw-r--r--ext/mbstring/libmbfl/mbfl/mbfilter.c14
-rw-r--r--ext/mbstring/tests/bug79787.phpt20
3 files changed, 32 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 6c35059e5e..eb336c22af 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,9 @@ PHP NEWS
- FTP:
. Fixed bug #55857 (ftp_size on large files). (cmb)
+- Mbstring:
+ . Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang)
+
- Reflection:
. Fixed bug #79487 (::getStaticProperties() ignores property modifications).
(cmb, Nikita)
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c
index 544eae9121..4da5a231a4 100644
--- a/ext/mbstring/libmbfl/mbfl/mbfilter.c
+++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c
@@ -1724,13 +1724,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;
diff --git a/ext/mbstring/tests/bug79787.phpt b/ext/mbstring/tests/bug79787.phpt
new file mode 100644
index 0000000000..c53c3b67f3
--- /dev/null
+++ b/ext/mbstring/tests/bug79787.phpt
@@ -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