ruby-changes:2721
From: ko1@a...
Date: 13 Dec 2007 18:10:16 +0900
Subject: [ruby-changes:2721] matz - Ruby:r14212 (trunk): * string.c (str_gsub): should copy encoding to the result.
matz 2007-12-13 18:05:49 +0900 (Thu, 13 Dec 2007) New Revision: 14212 Modified files: trunk/ChangeLog trunk/bootstraptest/test_knownbug.rb trunk/sprintf.c trunk/string.c Log: * string.c (str_gsub): should copy encoding to the result. * sprintf.c (rb_str_format): ditto. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=14212&r2=14211 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14212&r2=14211 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/sprintf.c?r1=14212&r2=14211 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14212&r2=14211 Index: ChangeLog =================================================================== --- ChangeLog (revision 14211) +++ ChangeLog (revision 14212) @@ -1,4 +1,4 @@ -Thu Dec 13 17:26:17 2007 Yukihiro Matsumoto <matz@r...> +Thu Dec 13 17:51:54 2007 Yukihiro Matsumoto <matz@r...> * string.c (rb_str_split_m): need not to check encoding if regexp is empty. @@ -9,6 +9,10 @@ * 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@r...> * encoding.c (rb_enc_compatible): should swap encoding indexes too. Index: bootstraptest/test_knownbug.rb =================================================================== --- bootstraptest/test_knownbug.rb (revision 14211) +++ bootstraptest/test_knownbug.rb (revision 14212) @@ -70,7 +70,7 @@ begin s["\xb0\xa3"] = "foo" :ng - rescue IndexError + rescue ArgumentError :ok end } Index: string.c =================================================================== --- string.c (revision 14211) +++ string.c (revision 14212) @@ -2490,11 +2490,12 @@ 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 @@ 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 @@ 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); Index: sprintf.c =================================================================== --- sprintf.c (revision 14211) +++ sprintf.c (revision 14212) @@ -848,6 +848,7 @@ rb_str_resize(result, blen); if (tainted) OBJ_TAINT(result); + rb_enc_associate(result, enc); return result; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml