summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--re.c10
-rw-r--r--test/ruby/test_regexp.rb16
-rw-r--r--version.h2
4 files changed, 25 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index bebb23d8f3..5904fcb64c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Aug 31 16:16:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * re.c (match_aref): should not ignore name after NUL byte.
+ [ruby-dev:48275] [Bug #9902]
+
Sun Aug 31 16:10:30 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/digest/digest.c (rb_digest_instance_equal): no need to call
diff --git a/re.c b/re.c
index 4e57971364..a9444ba97f 100644
--- a/re.c
+++ b/re.c
@@ -1728,17 +1728,13 @@ match_aref(int argc, VALUE *argv, VALUE match)
switch (TYPE(idx)) {
case T_SYMBOL:
- p = rb_id2name(SYM2ID(idx));
- goto name_to_backref;
- break;
+ idx = rb_id2str(SYM2ID(idx));
+ /* fall through */
case T_STRING:
p = StringValuePtr(idx);
-
- name_to_backref:
num = name_to_backref_number(RMATCH_REGS(match),
- RMATCH(match)->regexp, p, p + strlen(p));
+ RMATCH(match)->regexp, p, p + RSTRING_LEN(idx));
return rb_reg_nth_match(num, match);
- break;
default:
break;
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 5f719d40d7..28269fbd63 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -134,6 +134,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'))
diff --git a/version.h b/version.h
index 0108a3bef1..41a4c9777c 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2014-08-31"
-#define RUBY_PATCHLEVEL 534
+#define RUBY_PATCHLEVEL 535
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 8