mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
fb14b7eb05
commit
66bae8ad6d
4 changed files with 12 additions and 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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
8
string.c
8
string.c
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue