зеркало из https://github.com/github/ruby.git
string.c: infect match result
* string.c (rb_pat_search): match result should be infected by the pattern. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2f14bde88f
Коммит
9d1bf5b33a
1
re.c
1
re.c
|
@ -1235,6 +1235,7 @@ match_set_string(VALUE m, VALUE string, long pos, long len)
|
|||
rmatch->regs.beg[0] = pos;
|
||||
rmatch->regs.end[0] = pos + len;
|
||||
rmatch->char_offset_updated = 0;
|
||||
OBJ_INFECT(match, string);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
3
string.c
3
string.c
|
@ -3895,8 +3895,11 @@ rb_pat_search(VALUE pat, VALUE str, long pos, int set_backref_str)
|
|||
pos = rb_str_index(str, pat, pos);
|
||||
if (set_backref_str) {
|
||||
if (pos >= 0) {
|
||||
VALUE match;
|
||||
str = rb_str_new_frozen(str);
|
||||
rb_backref_set_string(str, pos, RSTRING_LEN(pat));
|
||||
match = rb_backref_get();
|
||||
OBJ_INFECT(match, pat);
|
||||
}
|
||||
else {
|
||||
rb_backref_set(Qnil);
|
||||
|
|
|
@ -1156,6 +1156,8 @@ class TestString < Test::Unit::TestCase
|
|||
/h/ =~ a
|
||||
a.scan('x')
|
||||
assert_nil($~)
|
||||
|
||||
assert_equal(3, S("hello hello hello").scan("hello".taint).count(&:tainted?))
|
||||
end
|
||||
|
||||
def test_size
|
||||
|
|
Загрузка…
Ссылка в новой задаче