Skip to content

Commit

Permalink
Add a ruby_bug spec for String#index clearing $~
Browse files Browse the repository at this point in the history
[Bug #20421]

The bug was fixed in Ruby 3.3 via 9dcdffb8bf8a3654fd78bf1a58b30c8e13888a7a
  • Loading branch information
byroot authored and andrykonchin committed May 9, 2024
1 parent 1abbf1c commit 506117a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/string/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@
$~.should == nil
end

ruby_bug "#20421", ""..."3.3" do
it "always clear $~" do
"a".index(/a/)
$~.should_not == nil

string = "blablabla"
string.index(/bla/, string.length + 1)
$~.should == nil
end
end

it "starts the search at the given offset" do
"blablabla".index(/.{0}/, 5).should == 5
"blablabla".index(/.{1}/, 5).should == 5
Expand Down

0 comments on commit 506117a

Please sign in to comment.