1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* re.c (rb_reg_regsub): should set checked encoding.

* string.c (rb_str_sub_bang): applied r14212 too.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-12-19 12:42:19 +00:00
parent 64a912155d
commit 474a88f041
4 changed files with 13 additions and 4 deletions

View file

@ -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.

2
re.c
View file

@ -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;
}

View file

@ -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) {

View file

@ -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