From 4960e66ab64350c6a6cc89b3b40fcd842dfa65d9 Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 28 Feb 2011 07:46:49 +0000 Subject: * string.c (tr_trans): when the hash for multibyte repl is empty, tr is inverse mode, and a character doesn't much the table, the character should be replaced by last replacement. Bug #4449 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ string.c | 2 +- test/ruby/test_m17n.rb | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cc87205b65..11b4a80b37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 28 16:28:15 2011 NARUSE, Yui + + * string.c (tr_trans): when the hash for multibyte repl is empty, + tr is inverse mode, and a character doesn't much the table, the + character should be replaced by last replacement. Bug #4449 + Mon Feb 28 16:38:56 2011 Tanaka Akira * ext/openssl/ossl_ocsp.c: parenthesize macro arguments. diff --git a/string.c b/string.c index 23784ab7fe..db8f761a0b 100644 --- a/string.c +++ b/string.c @@ -5060,7 +5060,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag) else c = NUM2INT(tmp); } else { - c = errc; + c = cflag ? last : errc; } if (c != errc) { tlen = rb_enc_codelen(c, enc); diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index a29d509fc4..c4bc9e6637 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -962,6 +962,7 @@ class TestM17N < Test::Unit::TestCase assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X")) assert_equal("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046")) + assert_equal("Y", "\u3042".tr("^X", "Y")) end def test_tr_s -- cgit v1.2.3