diff options
-rw-r--r-- | enc/trans/iso2022.trans | 14 | ||||
-rw-r--r-- | test/ruby/test_transcode.rb | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/enc/trans/iso2022.trans b/enc/trans/iso2022.trans index c2e65b329a..e77cf0fc30 100644 --- a/enc/trans/iso2022.trans +++ b/enc/trans/iso2022.trans @@ -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); diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index 144f4d83a1..63d37f4ba4 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -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 |