[Bug #18651] Pass undefined region in CP51932 as is to CP50220

This commit is contained in:
Nobuyoshi Nakada 2022-03-24 01:42:06 +09:00
parent 546f13fded
commit 75a8c937e7
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2024-09-20 07:59:01 +00:00
2 changed files with 13 additions and 3 deletions

View File

@ -453,9 +453,10 @@ fun_so_cp50220_encoder(void *statep, const unsigned char *s, size_t l,
unsigned char *output0 = o;
unsigned char *sp = statep;
if (sp[0] == G0_JISX0201_KATAKANA) {
if (sp[0] == G0_JISX0201_KATAKANA && sp[2]) {
int c = sp[2] & 0x7F;
const char *p = tbl0208 + (c - 0x21) * 2;
sp[2] = 0;
o = iso2022jp_put_state(sp, o, sp[1], G0_JISX0208_1983);
sp[0] = G0_JISX0208_1983;
*o++ = *p++;
@ -473,16 +474,23 @@ fun_so_cp50220_encoder(void *statep, const unsigned char *s, size_t l,
}
if (l == 2 && s[0] == 0x8E) {
const char *p = tbl0208 + (s[1] - 0xA1) * 2;
if ((0xA1 <= s[1] && s[1] <= 0xB5) ||
(0xC5 <= s[1] && s[1] <= 0xC9) ||
(0xCF <= s[1] && s[1] <= 0xDF)) {
const char *p = tbl0208 + (s[1] - 0xA1) * 2;
o = iso2022jp_put_state(sp, o, *sp, G0_JISX0208_1983);
*o++ = *p++;
*o++ = *p;
return o - output0;
}
if (s[1] > 0xDF) { /* undef */
o = iso2022jp_put_state(sp, o, *sp, G0_JISX0201_KATAKANA);
*o++ = s[1] & 0x7F;
sp[2] = 0;
return o - output0;
}
sp[2] = s[1];
sp[1] = sp[0];
sp[0] = G0_JISX0201_KATAKANA;
@ -502,7 +510,7 @@ finish_cp50220_encoder(void *statep, unsigned char *o, size_t osize)
if (*sp == G0_ASCII)
return 0;
if (sp[0] == G0_JISX0201_KATAKANA) {
if (sp[0] == G0_JISX0201_KATAKANA && sp[2]) {
int c = sp[2] & 0x7F;
const char *p = tbl0208 + (c - 0x21) * 2;
o = iso2022jp_put_state(sp, o, sp[1], G0_JISX0208_1983);

View File

@ -1634,6 +1634,8 @@ class TestTranscode < Test::Unit::TestCase
assert_equal("\e$B%*!+%,%I%J!+%N!+%P%\\%^!+%Q%]%\"\e(B".force_encoding("cp50220"),
"\xB5\xDE\xB6\xDE\xC4\xDE\xC5\xDE\xC9\xDE\xCA\xDE\xCE\xDE\xCF\xDE\xCA\xDF\xCE\xDF\xB1".
encode("cp50220", "sjis"))
assert_equal("\e$B\x21\x23\e(I\x7E\e(B".force_encoding("cp50220"),
"\x8E\xA1\x8E\xFE".encode("cp50220", "cp51932"))
end
def test_iso_2022_jp_1