diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-13 09:05:49 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-13 09:05:49 +0000 |
commit | 66bae8ad6df90c83b34908057afd991ffc9492c7 (patch) | |
tree | a5d63eccc053ea7d07ddfb2ca47bc3203f8558fd | |
parent | fb14b7eb05f9a2e378ebb69d2cbf001c3f4edbc3 (diff) |
* string.c (str_gsub): should copy encoding to the result.
* sprintf.c (rb_str_format): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | bootstraptest/test_knownbug.rb | 2 | ||||
-rw-r--r-- | sprintf.c | 1 | ||||
-rw-r--r-- | string.c | 8 |
4 files changed, 12 insertions, 5 deletions
@@ -1,4 +1,4 @@ -Thu Dec 13 17:26:17 2007 Yukihiro Matsumoto <matz@ruby-lang.org> +Thu Dec 13 17:51:54 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * string.c (rb_str_split_m): need not to check encoding if regexp is empty. @@ -9,6 +9,10 @@ Thu Dec 13 17:26:17 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * string.c (rb_str_chomp_bang): need to check encoding of record separator. + * string.c (str_gsub): should copy encoding to the result. + + * sprintf.c (rb_str_format): ditto. + Thu Dec 13 17:03:29 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> * encoding.c (rb_enc_compatible): should swap encoding indexes too. diff --git a/bootstraptest/test_knownbug.rb b/bootstraptest/test_knownbug.rb index 73829fb0aa..5bc093ecb1 100644 --- a/bootstraptest/test_knownbug.rb +++ b/bootstraptest/test_knownbug.rb @@ -70,7 +70,7 @@ assert_equal 'ok', %q{ begin s["\xb0\xa3"] = "foo" :ng - rescue IndexError + rescue ArgumentError :ok end } @@ -848,6 +848,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) rb_str_resize(result, blen); if (tainted) OBJ_TAINT(result); + rb_enc_associate(result, enc); return result; } @@ -2490,11 +2490,12 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) rb_str_locktmp(dest); do { + rb_encoding *enc; + n++; 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))); @@ -2505,12 +2506,12 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) 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); + enc = rb_enc_check(str, val); } + rb_enc_associate(str, enc); if (OBJ_TAINTED(val)) tainted = 1; len = (bp - buf) + (beg - offset) + RSTRING_LEN(val) + 3; if (blen < len) { @@ -2570,6 +2571,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) else { RBASIC(dest)->klass = rb_obj_class(str); OBJ_INFECT(dest, str); + rb_enc_copy(dest, str); str = dest; } STR_SET_LEN(str, bp - buf); |