diff --git a/ChangeLog b/ChangeLog index 112e8212c7..ea44ddb900 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Dec 12 12:11:42 2007 Nobuyoshi Nakada + + * re.c (rb_reg_regsub): should copy encoding. + + * string.c (rb_str_sub_bang, str_gsub): should check and copy encoding + to be replaced. + Tue Dec 11 23:04:17 2007 Yukihiro Matsumoto * pack.c (pack_pack): RDoc update. a patch from Gary Wright diff --git a/re.c b/re.c index 76c42c393f..ea6c644498 100644 --- a/re.c +++ b/re.c @@ -2796,6 +2796,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); return val; } diff --git a/string.c b/string.c index 9408b98245..2dadbbb82e 100644 --- a/string.c +++ b/string.c @@ -2370,15 +2370,19 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str) 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))); + enc = rb_enc_check(str, repl); 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); } rb_str_modify(str); if (OBJ_TAINTED(repl)) tainted = 1; @@ -2490,17 +2494,22 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) match = rb_backref_get(); regs = RMATCH(match)->regs; if (iter) { + rb_encoding *enc; + rb_match_busy(match); val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); + enc = rb_enc_check(str, val); str_mod_check(str, sp, slen); if (bang) str_frozen_check(str); if (val == dest) { /* paranoid chack [ruby-dev:24827] */ rb_raise(rb_eRuntimeError, "block should not cheat"); } rb_backref_set(match); + rb_enc_associate(str, enc); } else { val = rb_reg_regsub(repl, str, regs, pat); + rb_enc_copy(str, val); } if (OBJ_TAINTED(val)) tainted = 1; len = (bp - buf) + (beg - offset) + RSTRING_LEN(val) + 3; diff --git a/version.h b/version.h index d1de4cbee7..9168e76ea0 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-12-11" +#define RUBY_RELEASE_DATE "2007-12-12" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20071211 +#define RUBY_RELEASE_CODE 20071212 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 11 +#define RUBY_RELEASE_DAY 12 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[];