diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-20 15:27:35 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-20 15:27:35 +0000 |
| commit | 51405c8f7493a68992f5e858b55d3a922a24dbbf (patch) | |
| tree | e079fa6e038ce49b2289f80347f14fe48d8dff36 /string.c | |
| parent | 4f3e1f3fd709e5de0abc93e0cce52761e71bbad3 (diff) | |
| download | ruby-51405c8f7493a68992f5e858b55d3a922a24dbbf.tar.gz ruby-51405c8f7493a68992f5e858b55d3a922a24dbbf.tar.xz ruby-51405c8f7493a68992f5e858b55d3a922a24dbbf.zip | |
* 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
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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); |
