* 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:
parent
64a912155d
commit
474a88f041
@ -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>
|
Wed Dec 19 20:40:01 2007 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* bignum.c (bigmul1): C99ism.
|
* bignum.c (bigmul1): C99ism.
|
||||||
|
2
re.c
2
re.c
@ -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);
|
rb_str_buf_cat(val, p, e-p);
|
||||||
}
|
}
|
||||||
if (!val) return str;
|
if (!val) return str;
|
||||||
rb_enc_copy(val, str);
|
rb_enc_associate(val, enc);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
7
string.c
7
string.c
@ -2401,12 +2401,13 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
|
|||||||
|
|
||||||
pat = get_pat(argv[0], 1);
|
pat = get_pat(argv[0], 1);
|
||||||
if (rb_reg_search(pat, str, 0, 0) >= 0) {
|
if (rb_reg_search(pat, str, 0, 0) >= 0) {
|
||||||
|
rb_encoding *enc;
|
||||||
|
|
||||||
match = rb_backref_get();
|
match = rb_backref_get();
|
||||||
regs = RMATCH(match)->regs;
|
regs = RMATCH(match)->regs;
|
||||||
|
|
||||||
if (iter) {
|
if (iter) {
|
||||||
char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str);
|
char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str);
|
||||||
rb_encoding *enc;
|
|
||||||
|
|
||||||
rb_match_busy(match);
|
rb_match_busy(match);
|
||||||
repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, 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_mod_check(str, p, len);
|
||||||
str_frozen_check(str);
|
str_frozen_check(str);
|
||||||
rb_backref_set(match);
|
rb_backref_set(match);
|
||||||
rb_enc_associate(str, enc);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
repl = rb_reg_regsub(repl, str, regs, pat);
|
repl = rb_reg_regsub(repl, str, regs, pat);
|
||||||
rb_enc_copy(str, repl);
|
enc = rb_enc_check(str, repl);
|
||||||
}
|
}
|
||||||
rb_str_modify(str);
|
rb_str_modify(str);
|
||||||
|
rb_enc_associate(str, enc);
|
||||||
if (OBJ_TAINTED(repl)) tainted = 1;
|
if (OBJ_TAINTED(repl)) tainted = 1;
|
||||||
plen = END(0) - BEG(0);
|
plen = END(0) - BEG(0);
|
||||||
if (RSTRING_LEN(repl) > plen) {
|
if (RSTRING_LEN(repl) > plen) {
|
||||||
|
@ -1377,6 +1377,8 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
def test_sub
|
def test_sub
|
||||||
s = "abc".sub(/b/, "\xa1\xa1".force_encoding("euc-jp"))
|
s = "abc".sub(/b/, "\xa1\xa1".force_encoding("euc-jp"))
|
||||||
assert_encoding("EUC-JP", s.encoding)
|
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
|
end
|
||||||
|
|
||||||
def test_regexp_match
|
def test_regexp_match
|
||||||
|
Loading…
x
Reference in New Issue
Block a user