mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: unset $~ if unmatch
* string.c (rb_pat_search): unset $~ if the last match failed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
209a310c47
commit
2d82342cf2
2 changed files with 16 additions and 3 deletions
11
string.c
11
string.c
|
@ -3893,9 +3893,14 @@ rb_pat_search(VALUE pat, VALUE str, long pos, int set_backref_str)
|
|||
{
|
||||
if (BUILTIN_TYPE(pat) == T_STRING) {
|
||||
pos = rb_str_index(str, pat, pos);
|
||||
if (pos >= 0 && set_backref_str) {
|
||||
str = rb_str_new_frozen(str);
|
||||
rb_backref_set_string(str, pos, RSTRING_LEN(pat));
|
||||
if (set_backref_str) {
|
||||
if (pos >= 0) {
|
||||
str = rb_str_new_frozen(str);
|
||||
rb_backref_set_string(str, pos, RSTRING_LEN(pat));
|
||||
}
|
||||
else {
|
||||
rb_backref_set(Qnil);
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
|
|
@ -1147,6 +1147,14 @@ class TestString < Test::Unit::TestCase
|
|||
res = []
|
||||
a.scan(/./) { |w| res << w }
|
||||
assert_predicate(res[0], :tainted?, '[ruby-core:33338] #4087')
|
||||
|
||||
/h/ =~ a
|
||||
a.scan(/x/)
|
||||
assert_nil($~)
|
||||
|
||||
/h/ =~ a
|
||||
a.scan('x')
|
||||
assert_nil($~)
|
||||
end
|
||||
|
||||
def test_size
|
||||
|
|
Loading…
Add table
Reference in a new issue