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

ruby-changes:35282

From: usa <ko1@a...>
Date: Wed, 3 Sep 2014 12:27:53 +0900 (JST)
Subject: [ruby-changes:35282] usa:r47364 (ruby_2_0_0): merge revision(s) 42251, 46345, 46346: [Backport #9903]

usa	2014-09-03 12:27:43 +0900 (Wed, 03 Sep 2014)

  New Revision: 47364

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

  Log:
    merge revision(s) 42251,46345,46346: [Backport #9903]
    
    * sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
      characters.
    
    * sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
      characters.
    
    * re.c (match_aref, rb_reg_regsub): consider encoding of captured
      names, encoding-incompatible should not match.
      [ruby-dev:48278] [Bug #9903]

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/ext/-test-/printf/printf.c
    branches/ruby_2_0_0/re.c
    branches/ruby_2_0_0/sprintf.c
    branches/ruby_2_0_0/test/-ext-/test_printf.rb
    branches/ruby_2_0_0/test/ruby/test_regexp.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 47363)
+++ ruby_2_0_0/ChangeLog	(revision 47364)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Wed Sep  3 12:24:39 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* re.c (match_aref, rb_reg_regsub): consider encoding of captured
+	  names, encoding-incompatible should not match.
+	  [ruby-dev:48278] [Bug #9903]
+
+Wed Sep  3 12:24:39 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
+	  characters.
+
+Wed Sep  3 12:24:39 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
+	  characters.
+
 Sun Aug 31 16:59:45 2014  Koichi Sasada  <ko1@a...>
 
 	* vm_eval.c (rb_catch_protect): fix same problem of [Bug #9961].
Index: ruby_2_0_0/re.c
===================================================================
--- ruby_2_0_0/re.c	(revision 47363)
+++ ruby_2_0_0/re.c	(revision 47364)
@@ -1665,20 +1665,16 @@ match_captures(VALUE match) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/re.c#L1665
 static int
 name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
 {
-    int num;
-
-    num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
+    return onig_name_to_backref_number(RREGEXP(regexp)->ptr,
 	(const unsigned char* )name, (const unsigned char* )name_end, regs);
-    if (num >= 1) {
-	return num;
-    }
-    else {
-	VALUE s = rb_str_new(name, (long )(name_end - name));
-	rb_raise(rb_eIndexError, "undefined group name reference: %s",
-				 StringValuePtr(s));
-    }
+}
 
-    UNREACHABLE;
+NORETURN(static void name_to_backref_error(VALUE name));
+static void
+name_to_backref_error(VALUE name)
+{
+    rb_raise(rb_eIndexError, "undefined group name reference: % "PRIsVALUE,
+	     name);
 }
 
 /*
@@ -1732,8 +1728,11 @@ match_aref(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/re.c#L1728
 		/* fall through */
 	      case T_STRING:
 		p = StringValuePtr(idx);
-		num = name_to_backref_number(RMATCH_REGS(match),
-					     RMATCH(match)->regexp, p, p + RSTRING_LEN(idx));
+		if (!rb_enc_compatible(RREGEXP(RMATCH(match)->regexp)->src, idx) ||
+		    (num = name_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp,
+						  p, p + RSTRING_LEN(idx))) < 1) {
+		    name_to_backref_error(idx);
+		}
 		return rb_reg_nth_match(num, match);
 
 	      default:
@@ -3342,7 +3341,12 @@ rb_reg_regsub(VALUE str, VALUE src, stru https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/re.c#L3341
                     name_end += c == -1 ? mbclen(name_end, e, str_enc) : clen;
                 }
                 if (name_end < e) {
-                    no = name_to_backref_number(regs, regexp, name, name_end);
+		    VALUE n = rb_str_subseq(str, (long)(name - RSTRING_PTR(str)),
+					    (long)(name_end - name));
+		    if (!rb_enc_compatible(RREGEXP(regexp)->src, n) ||
+			(no = name_to_backref_number(regs, regexp, name, name_end)) < 1) {
+			name_to_backref_error(n);
+		    }
                     p = s = name_end + clen;
                     break;
                 }
Index: ruby_2_0_0/sprintf.c
===================================================================
--- ruby_2_0_0/sprintf.c	(revision 47363)
+++ ruby_2_0_0/sprintf.c	(revision 47364)
@@ -14,6 +14,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/sprintf.c#L14
 #include "ruby/ruby.h"
 #include "ruby/re.h"
 #include "ruby/encoding.h"
+#include "internal.h"
 #include <math.h>
 #include <stdarg.h>
 
@@ -1195,6 +1196,7 @@ ruby__sfvextra(rb_printf_buffer *fp, siz https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/sprintf.c#L1196
     }
     else {
 	value = rb_obj_as_string(value);
+	if (sign == ' ') value = QUOTE(value);
     }
     enc = rb_enc_compatible(result, value);
     if (enc) {
Index: ruby_2_0_0/ext/-test-/printf/printf.c
===================================================================
--- ruby_2_0_0/ext/-test-/printf/printf.c	(revision 47363)
+++ ruby_2_0_0/ext/-test-/printf/printf.c	(revision 47364)
@@ -106,4 +106,5 @@ Init_printf(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/-test-/printf/printf.c#L106
     rb_define_singleton_method(m, "s", printf_test_s, 1);
     rb_define_singleton_method(m, "v", printf_test_v, 1);
     rb_define_singleton_method(m, "call", printf_test_call, -1);
+    rb_define_singleton_method(m, "q", printf_test_q, 1);
 }
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 47363)
+++ ruby_2_0_0/version.h	(revision 47364)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
-#define RUBY_RELEASE_DATE "2014-08-31"
-#define RUBY_PATCHLEVEL 542
+#define RUBY_RELEASE_DATE "2014-09-03"
+#define RUBY_PATCHLEVEL 543
 
 #define RUBY_RELEASE_YEAR 2014
-#define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 31
+#define RUBY_RELEASE_MONTH 9
+#define RUBY_RELEASE_DAY 3
 
 #include "ruby/version.h"
 
Index: ruby_2_0_0/test/ruby/test_regexp.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_regexp.rb	(revision 47363)
+++ ruby_2_0_0/test/ruby/test_regexp.rb	(revision 47364)
@@ -150,6 +150,15 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_regexp.rb#L150
     }
   end
 
+  def test_named_capture_nonascii
+    bug9903 = '[ruby-dev:48278] [Bug #9903]'
+
+    key = "\xb1\xb2".force_encoding(Encoding::EUC_JP)
+    m = /(?<#{key}>.*)/.match("xxx")
+    assert_equal("xxx", m[key])
+    assert_raise(IndexError, bug9903) {m[key.dup.force_encoding(Encoding::Shift_JIS)]}
+  end
+
   def test_assign_named_capture
     assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
     assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))
Index: ruby_2_0_0/test/-ext-/test_printf.rb
===================================================================
--- ruby_2_0_0/test/-ext-/test_printf.rb	(revision 47363)
+++ ruby_2_0_0/test/-ext-/test_printf.rb	(revision 47364)
@@ -22,6 +22,12 @@ class Test_SPrintf < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/-ext-/test_printf.rb#L22
     assert_equal("{<#{self.class}:#{object_id}>}", Bug::Printf.v(self))
   end
 
+  def test_quote
+    assert_equal('["\n"]', Bug::Printf.q("\n"))
+    assert_equal('[aaa]', Bug::Printf.q('aaa'))
+    assert_equal('[a a]', Bug::Printf.q('a a'))
+  end
+
   def test_encoding
     def self.to_s
       "\u{3042 3044 3046 3048 304a}"

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r42251,46345-46346


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

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