summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--test/ruby/test_transcode.rb5
-rw-r--r--transcode.c16
3 files changed, 21 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 1153c59e9e..5cfc8bed4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Aug 12 06:48:35 2008 Tanaka Akira <akr@fsij.org>
+
+ * transcode.c (rb_trans_conv): find second last error.
+
Tue Aug 12 00:43:44 2008 Tanaka Akira <akr@fsij.org>
* transcode_data.h (rb_trans_result_t): new type.
diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb
index deffee58f3..8664f443a0 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 b01903cdb5..a733a054ab 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;
+ }
}
}