From 93a873eca85a3c80cd19d3de3ad70285bef709b3 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 11 Aug 2008 21:49:38 +0000 Subject: * transcode.c (rb_trans_conv): find second last error. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ test/ruby/test_transcode.rb | 5 +++++ transcode.c | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1153c59e9..5cfc8bed4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Aug 12 06:48:35 2008 Tanaka Akira + + * transcode.c (rb_trans_conv): find second last error. + Tue Aug 12 00:43:44 2008 Tanaka Akira * transcode_data.h (rb_trans_result_t): new type. diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index deffee58f..8664f443a 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -298,6 +298,11 @@ class TestTranscode < Test::Unit::TestCase "\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace)) assert_equal("\uFFFD!", "\x8f\xa1!".encode("utf-8", "euc-jp", :invalid=>:replace)) + + assert_equal("?", + "\xdc\x00".encode("EUC-JP", "UTF-16BE", :invalid=>:replace), "[ruby-dev:35776]") + assert_equal("ab?cd?ef", + "\0a\0b\xdc\x00\0c\0d\xdf\x00\0e\0f".encode("EUC-JP", "UTF-16BE", :invalid=>:replace)) end def test_undef_replace diff --git a/transcode.c b/transcode.c index b01903cdb..a733a054a 100644 --- a/transcode.c +++ b/transcode.c @@ -736,7 +736,7 @@ rb_trans_conv(rb_trans_t *ts, int flags) { int i; - int start, err_index; + int start, err_index, no_error; unsigned char empty_buf; unsigned char *empty_ptr = &empty_buf; @@ -751,12 +751,20 @@ rb_trans_conv(rb_trans_t *ts, output_stop = empty_ptr; } + no_error = 1; err_index = -1; - for (i = ts->num_trans-2; 0 <= i; i--) { + for (i = ts->num_trans-1; 0 <= i; i--) { if (ts->elems[i].last_result == transcode_invalid_input || ts->elems[i].last_result == transcode_undefined_conversion) { - err_index = i; - break; + if (no_error) { + /* last error */ + no_error = 0; + } + else { + /* second last error */ + err_index = i; + break; + } } } -- cgit