From 51405c8f7493a68992f5e858b55d3a922a24dbbf 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: http://svn.ruby-lang.org/repos/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 f1910af78..eecfc6347 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