]> granicus.if.org Git - php/commitdiff
Fix bug #79787
authorXXiang <x.xiang@outlook.com>
Sat, 4 Jul 2020 14:12:57 +0000 (22:12 +0800)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 8 Jul 2020 09:20:58 +0000 (11:20 +0200)
Closes GH-5807.

NEWS
ext/mbstring/libmbfl/mbfl/mbfilter.c
ext/mbstring/tests/bug79787.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 17289b59e0433b51e38a2381cb008812ebf25f94..071e456a8894b442a74b349ec1c231cf2273b695 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
 
index 313ea598fc0cee4d37c700455ae76a086623441e..fdbbb9d2a92b871983d23238db1b9a42205af43a 100644 (file)
@@ -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;
diff --git a/ext/mbstring/tests/bug79787.phpt b/ext/mbstring/tests/bug79787.phpt
new file mode 100644 (file)
index 0000000..c53c3b6
--- /dev/null
@@ -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