[前][次][番号順一覧][スレッド一覧]

ruby-changes:34786

From: nagachika <ko1@a...>
Date: Sat, 19 Jul 2014 01:47:01 +0900 (JST)
Subject: [ruby-changes:34786] nagachika:r46869 (ruby_2_1): merge revision(s) r46344: [Backport #9902]

nagachika	2014-07-19 01:46:45 +0900 (Sat, 19 Jul 2014)

  New Revision: 46869

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46869

  Log:
    merge revision(s) r46344: [Backport #9902]
    
    * re.c (match_aref): should not ignore name after NUL byte.
      [ruby-dev:48275] [Bug #9902]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/re.c
    branches/ruby_2_1/test/ruby/test_regexp.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46868)
+++ ruby_2_1/ChangeLog	(revision 46869)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Sat Jul 19 01:44:34 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* re.c (match_aref): should not ignore name after NUL byte.
+	  [ruby-dev:48275] [Bug #9902]
+
 Sun Jul 13 23:28:41 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* test/test_timeout.rb (test_timeout): inverted test condition.
Index: ruby_2_1/re.c
===================================================================
--- ruby_2_1/re.c	(revision 46868)
+++ ruby_2_1/re.c	(revision 46869)
@@ -1754,17 +1754,13 @@ match_aref(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/re.c#L1754
 
 	    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;
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46868)
+++ ruby_2_1/version.h	(revision 46869)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-07-13"
-#define RUBY_PATCHLEVEL 175
+#define RUBY_RELEASE_DATE "2014-07-19"
+#define RUBY_PATCHLEVEL 176
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 7
-#define RUBY_RELEASE_DAY 13
+#define RUBY_RELEASE_DAY 19
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_regexp.rb
===================================================================
--- ruby_2_1/test/ruby/test_regexp.rb	(revision 46868)
+++ ruby_2_1/test/ruby/test_regexp.rb	(revision 46869)
@@ -142,6 +142,22 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_regexp.rb#L142
     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'))

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46344


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]