diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index 313ea598fc0ce..fdbbb9d2a92b8 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 0000000000000..c53c3b67f3e8c --- /dev/null +++ b/ext/mbstring/tests/bug79787.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #79787 mb_strimwidth does not trim string +--SKIPIF-- + +--FILE-- + +--EXPECT-- +一. +一二. +一二三 +abc. +abcd. +abcdef