From cfb91bc2f57050e853b330b5bf497fea4c19e0f4 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 20 Dec 2007 15:27:35 +0000 Subject: * string.c (tr_trans): wrong encoding check for tree strings. * test/ruby/test_m17n.rb (TestM17N::test_tr_s): "invalid mbstring sequence" is not an error to be tested. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index f1910af782..eecfc6347d 100644 --- a/string.c +++ b/string.c @@ -3453,7 +3453,7 @@ static VALUE tr_trans(VALUE str, VALUE src, VALUE repl, int sflag) { SIGNED_VALUE trans[256]; - rb_encoding *enc; + rb_encoding *enc, *e1, *e2; struct tr trsrc, trrepl; int cflag = 0; int c, last = 0, modify = 0, i; @@ -3471,9 +3471,13 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag) if (RSTRING_LEN(repl) == 0) { return rb_str_delete_bang(1, &src, str); } - enc = rb_enc_check(str, src); - if (rb_enc_check(str, repl) != enc) { - rb_raise(rb_eArgError, "character encodings differ"); + e1 = rb_enc_check(str, src); + e2 = rb_enc_check(str, repl); + if (e1 == e2) { + enc = e1; + } + else { + enc = rb_enc_check(src, repl); } trrepl.p = RSTRING_PTR(repl); trrepl.pend = trrepl.p + RSTRING_LEN(repl); -- cgit v1.2.3