summaryrefslogtreecommitdiff
path: root/test/ruby/test_regexp.rb
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-18 16:46:45 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-18 16:46:45 +0000
commitf8048f78177a5151ef31f9f0d6176caaface59af (patch)
tree3c94a93e55ef9ad361b5625bc61a0b8cd10320cb /test/ruby/test_regexp.rb
parent30c0ad5563630200a779d2e9c7e01fae98e94968 (diff)
merge revision(s) r46344: [Backport #9902]
* re.c (match_aref): should not ignore name after NUL byte. [ruby-dev:48275] [Bug #9902] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_regexp.rb')
-rw-r--r--test/ruby/test_regexp.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index cff2bb6d1f..b4b29a6368 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -142,6 +142,22 @@ class TestRegexp < Test::Unit::TestCase
assert_equal("fbazo", s)
end
+ def test_named_capture_with_nul
+ bug9902 = '[ruby-dev:48275] [Bug #9902]'
+
+ m = /(?<a>.*)/.match("foo")
+ assert_raise(IndexError, bug9902) {m["a\0foo"]}
+ assert_raise(IndexError, bug9902) {m["a\0foo".to_sym]}
+
+ m = Regexp.new("(?<foo\0bar>.*)").match("xxx")
+ assert_raise(IndexError, bug9902) {m["foo"]}
+ assert_raise(IndexError, bug9902) {m["foo".to_sym]}
+ assert_nothing_raised(IndexError, bug9902) {
+ assert_equal("xxx", m["foo\0bar"], bug9902)
+ assert_equal("xxx", m["foo\0bar".to_sym], bug9902)
+ }
+ end
+
def test_assign_named_capture
assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))