Skip to content

Commit b0d606d

Browse files
committed
fix php#9535
1 parent 3d5df06 commit b0d606d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ mbfl_strcut(
10971097
mbfl_convert_filter *encoder = NULL;
10981098
mbfl_convert_filter *decoder = NULL;
10991099
const unsigned char *p, *q, *r;
1100+
int original_pos = 0;
11001101
struct {
11011102
mbfl_convert_filter encoder;
11021103
mbfl_convert_filter decoder;
@@ -1276,7 +1277,11 @@ mbfl_strcut(
12761277
bk = _bk;
12771278
}
12781279

1279-
(*encoder->filter_flush)(encoder);
1280+
if (device.pos != 0) {
1281+
original_pos = device.pos;
1282+
(*encoder->filter_flush)(encoder);
1283+
device.pos = original_pos;
1284+
}
12801285

12811286
if (bk.decoder.filter_dtor)
12821287
bk.decoder.filter_dtor(&bk.decoder);

ext/mbstring/tests/gh9535.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-9535 (mb_strcut(): The behavior of mb_strcut in mbstring has been changed in PHP8.1)
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
$input = 'あaいb';
8+
$bytes_length = 10;
9+
$encoding = "ISO-2022-JP";
10+
$converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding());
11+
$cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding);
12+
$reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding);
13+
var_dump($reconverted_str);
14+
?>
15+
--EXPECT--
16+
string(4) "あa"

0 commit comments

Comments
 (0)