diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | re.c | 2 | ||||
-rw-r--r-- | string.c | 7 | ||||
-rw-r--r-- | test/ruby/test_m17n.rb | 2 |
4 files changed, 13 insertions, 4 deletions
@@ -1,3 +1,9 @@ +Wed Dec 19 21:42:18 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * re.c (rb_reg_regsub): should set checked encoding. + + * string.c (rb_str_sub_bang): applied r14212 too. + Wed Dec 19 20:40:01 2007 NAKAMURA Usaku <usa@ruby-lang.org> * bignum.c (bigmul1): C99ism. @@ -2832,7 +2832,7 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp) rb_str_buf_cat(val, p, e-p); } if (!val) return str; - rb_enc_copy(val, str); + rb_enc_associate(val, enc); return val; } @@ -2401,12 +2401,13 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str) pat = get_pat(argv[0], 1); if (rb_reg_search(pat, str, 0, 0) >= 0) { + rb_encoding *enc; + match = rb_backref_get(); regs = RMATCH(match)->regs; if (iter) { char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str); - rb_encoding *enc; rb_match_busy(match); repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); @@ -2414,13 +2415,13 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str) str_mod_check(str, p, len); str_frozen_check(str); rb_backref_set(match); - rb_enc_associate(str, enc); } else { repl = rb_reg_regsub(repl, str, regs, pat); - rb_enc_copy(str, repl); + enc = rb_enc_check(str, repl); } rb_str_modify(str); + rb_enc_associate(str, enc); if (OBJ_TAINTED(repl)) tainted = 1; plen = END(0) - BEG(0); if (RSTRING_LEN(repl) > plen) { diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index a838341b22..3681a8e15d 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1377,6 +1377,8 @@ class TestM17N < Test::Unit::TestCase def test_sub s = "abc".sub(/b/, "\xa1\xa1".force_encoding("euc-jp")) assert_encoding("EUC-JP", s.encoding) + assert_equal(Encoding::EUC_JP, "\xa4\xa2".force_encoding("euc-jp").sub(/./, '\&').encoding) + assert_equal(Encoding::EUC_JP, "\xa4\xa2".force_encoding("euc-jp").gsub(/./, '\&').encoding) end def test_regexp_match |