From f943db90f6666a466206693160197a17e513348b Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Sat, 28 Nov 2026 11:47:14 +0100 Subject: [PATCH] ext/mbstring: Re-designate JIS X 0213 plane on switch in ISO-2022-JP-2004 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. --- ext/mbstring/libmbfl/filters/mbfilter_cjk.c | 4 ++-- .../mb_strcut_iso2022jp2004_plane_switch.phpt | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 ext/mbstring/tests/mb_strcut_iso2022jp2004_plane_switch.phpt diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cjk.c b/ext/mbstring/libmbfl/filters/mbfilter_cjk.c index 1c158a852c3a..2fad3a1d93e7 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cjk.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cjk.c @@ -2031,13 +2031,13 @@ static int mbfl_filt_conv_wchar_jis2004(int c, mbfl_convert_filter *filter) s1 |= 0x80; CK((*filter->output_function)(0x8f, filter->data)); } else { - if ((filter->status & 0xff00) != 0x200) { + if ((filter->status & 0xff00) != 0x300) { CK((*filter->output_function)(0x1b, filter->data)); /* ESC */ CK((*filter->output_function)('$', filter->data)); CK((*filter->output_function)('(', filter->data)); CK((*filter->output_function)('P', filter->data)); } - filter->status = 0x200; + filter->status = 0x300; } } diff --git a/ext/mbstring/tests/mb_strcut_iso2022jp2004_plane_switch.phpt b/ext/mbstring/tests/mb_strcut_iso2022jp2004_plane_switch.phpt new file mode 100644 index 000000000000..5ceb3e0eafe3 --- /dev/null +++ b/ext/mbstring/tests/mb_strcut_iso2022jp2004_plane_switch.phpt @@ -0,0 +1,16 @@ +--TEST-- +mb_strcut() re-designates JIS X 0213 plane when switching between planes 1 and 2 in ISO-2022-JP-2004 +--EXTENSIONS-- +mbstring +--FILE-- + +--EXPECT-- +1b2428512e211b24285021211b2842 true e4bfb1f0a08289 +1b24285021211b2428512e211b2842 true f0a08289e4bfb1 +1b24285021211b2428512b5a1b2842 true f0a08289cc81