diff options
author | XXiang <x.xiang@outlook.com> | 2020-07-04 22:12:57 +0800 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-07-08 11:20:58 +0200 |
commit | 3d5de7d74660b1ba6ae92a91581f7a50573554dc (patch) | |
tree | 4cbfea2fc62b1dd40eb566d85378c15d925a62ef | |
parent | e6160e99d8525c30420a9c8418e798d3e33f26a3 (diff) | |
download | php-git-3d5de7d74660b1ba6ae92a91581f7a50573554dc.tar.gz |
Fix bug #79787
Closes GH-5807.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfilter.c | 14 | ||||
-rw-r--r-- | ext/mbstring/tests/bug79787.phpt | 20 |
3 files changed, 32 insertions, 5 deletions
@@ -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) diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index 313ea598fc..fdbbb9d2a9 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c @@ -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 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 |