Skip to content

Commit 33ad78c

Browse files
committed
ext/mbstring: Re-designate JIS X 0213 plane on switch in ISO-2022-JP-2004 (GH-25871)
Plane 1 and plane 2 shared the same status value, so switching between them omitted the ESC $ ( Q / ESC $ ( P designation and the following characters decoded as the wrong plane. Closes GH-25871
1 parent beed61d commit 33ad78c

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ PHP NEWS
129129
deeply nested arrays. (Eyüp Can Akman)
130130
. Fixed the JIT freeing the string returned by mb_encode_mimeheader() or
131131
mb_output_handler() while it is still in use. (Ilia Alshanetsky)
132+
. Fixed ISO-2022-JP-2004 output omitting the plane designation when switching
133+
between JIS X 0213 plane 1 and plane 2. (Jorg Sowa)
132134

133135
- MySQLi:
134136
. Fixed bug GH-25779 (mysqli_fetch_object() crashes with JIT when the

‎ext/mbstring/libmbfl/filters/mbfilter_cjk.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,13 +2031,13 @@ static int mbfl_filt_conv_wchar_jis2004(int c, mbfl_convert_filter *filter)
20312031
s1 |= 0x80;
20322032
CK((*filter->output_function)(0x8f, filter->data));
20332033
} else {
2034-
if ((filter->status & 0xff00) != 0x200) {
2034+
if ((filter->status & 0xff00) != 0x300) {
20352035
CK((*filter->output_function)(0x1b, filter->data)); /* ESC */
20362036
CK((*filter->output_function)('$', filter->data));
20372037
CK((*filter->output_function)('(', filter->data));
20382038
CK((*filter->output_function)('P', filter->data));
20392039
}
2040-
filter->status = 0x200;
2040+
filter->status = 0x300;
20412041
}
20422042
}
20432043

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
mb_strcut() re-designates JIS X 0213 plane when switching between planes 1 and 2 in ISO-2022-JP-2004
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
foreach (["\u{4FF1}\u{20089}", "\u{20089}\u{4FF1}", "\u{20089}\u{301}"] as $u) {
8+
$s = mb_convert_encoding($u, 'ISO-2022-JP-2004', 'UTF-8');
9+
$cut = mb_strcut($s, 0, strlen($s), 'ISO-2022-JP-2004');
10+
echo bin2hex($cut), ' ', var_export($cut === $s, true), ' ', bin2hex(mb_convert_encoding($cut, 'UTF-8', 'ISO-2022-JP-2004')), "\n";
11+
}
12+
?>
13+
--EXPECT--
14+
1b2428512e211b24285021211b2842 true e4bfb1f0a08289
15+
1b24285021211b2428512e211b2842 true f0a08289e4bfb1
16+
1b24285021211b2428512b5a1b2842 true f0a08289cc81

0 commit comments

Comments
 (0)