re.c: RMatch::regexp can be nil

* re.c (match_aref): RMatch::regexp is Qnil after matching by a
  string since r45451.  [ruby-core:68209] [Bug #10877]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-02-21 10:51:52 +00:00
parent 516e463aaf
commit 2d12151a68
3 changed files with 21 additions and 2 deletions

View file

@ -545,6 +545,19 @@ class TestRegexp < Test::Unit::TestCase
assert_equal("foo", $&)
end
def test_match_without_regexp
bug10877 = '[ruby-core:68209] [Bug #10877]'
"abc".sub("a", "")
assert_raise_with_message(IndexError, /foo/, bug10877) {$~["foo"]}
key = "\u{3042}"
[Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
idx = key.encode(enc)
EnvUtil.with_default_external(enc) do
assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]}
end
end
end
def test_last_match
/(...)(...)(...)(...)?/.match("foobarbaz")
assert_equal("foobarbaz", Regexp.last_match(0))