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

ruby-changes:35415

From: usa <ko1@a...>
Date: Wed, 10 Sep 2014 12:05:42 +0900 (JST)
Subject: [ruby-changes:35415] usa:r47497 (ruby_2_0_0): merge revision(s) 46569: [Backport #9982]

usa	2014-09-10 12:05:22 +0900 (Wed, 10 Sep 2014)

  New Revision: 47497

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

  Log:
    merge revision(s) 46569: [Backport #9982]
    
    * sprintf.c (GETASTER): should not use the numbered argument to be
      formatted, raise ArgumentError instead.
      [ruby-dev:48330] [Bug #9982]

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/sprintf.c
    branches/ruby_2_0_0/test/ruby/envutil.rb
    branches/ruby_2_0_0/test/ruby/test_sprintf.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 47496)
+++ ruby_2_0_0/ChangeLog	(revision 47497)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Wed Sep 10 11:50:26 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* sprintf.c (GETASTER): should not use the numbered argument to be
+	  formatted, raise ArgumentError instead.
+	  [ruby-dev:48330] [Bug #9982]
+
 Wed Sep 10 11:43:55 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* test/openssl/test_pkey_rsa.rb (OpenSSL#test_sign_verify_memory_leak):
Index: ruby_2_0_0/sprintf.c
===================================================================
--- ruby_2_0_0/sprintf.c	(revision 47496)
+++ ruby_2_0_0/sprintf.c	(revision 47497)
@@ -104,6 +104,9 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/sprintf.c#L104
 } while (0)
 
 #define GETARG() (nextvalue != Qundef ? nextvalue : \
+		  GETNEXTARG())
+
+#define GETNEXTARG() ( \
     posarg == -1 ? \
     (rb_raise(rb_eArgError, "unnumbered(%d) mixed with numbered", nextarg), 0) : \
     posarg == -2 ? \
@@ -147,7 +150,7 @@ sign_bits(int base, const char *p) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/sprintf.c#L150
 	tmp = GETPOSARG(n); \
     } \
     else { \
-	tmp = GETARG(); \
+	tmp = GETNEXTARG(); \
 	p = t; \
     } \
     (val) = NUM2INT(tmp); \
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 47496)
+++ ruby_2_0_0/version.h	(revision 47497)
@@ -1,6 +1,6 @@ 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-09-10"
-#define RUBY_PATCHLEVEL 558
+#define RUBY_PATCHLEVEL 559
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 9
Index: ruby_2_0_0/test/ruby/test_sprintf.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_sprintf.rb	(revision 47496)
+++ ruby_2_0_0/test/ruby/test_sprintf.rb	(revision 47497)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_sprintf.rb#L1
 require 'test/unit'
+require_relative 'envutil'
 
 class TestSprintf < Test::Unit::TestCase
   def test_positional
@@ -179,6 +180,10 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_sprintf.rb#L180
     assert_raise(ArgumentError) { sprintf("%!", 1) }
     assert_raise(ArgumentError) { sprintf("%1$1$d", 1) }
     assert_raise(ArgumentError) { sprintf("%0%") }
+
+    assert_raise_with_message(ArgumentError, /unnumbered\(1\) mixed with numbered/) { sprintf("%1$*d", 3) }
+    assert_raise_with_message(ArgumentError, /unnumbered\(1\) mixed with numbered/) { sprintf("%1$.*d", 3) }
+
     verbose, $VERBOSE = $VERBOSE, nil
     assert_nothing_raised { sprintf("", 1) }
   ensure
Index: ruby_2_0_0/test/ruby/envutil.rb
===================================================================
--- ruby_2_0_0/test/ruby/envutil.rb	(revision 47496)
+++ ruby_2_0_0/test/ruby/envutil.rb	(revision 47497)
@@ -423,6 +423,26 @@ eom https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/envutil.rb#L423
           clone.tap {|a| a.message = message}
         end
       end
+
+      # derived from MiniTest 2.1.0
+      def assert_raise_with_message(exception, expected, msg = nil, &block)
+        case expected
+        when String
+          assert = :assert_equal
+        when Regexp
+          assert = :assert_match
+        else
+          raise TypeError, "Expected #{expected.inspect} to be a kind of String or Regexp, not #{expected.class}"
+        end
+
+        ex = assert_raise(exception, *msg) { yield }
+        if assert == :assert_equal
+          assert_equal(expected, ex.message, msg || "Expected exception(#{exception}) was raised, but the message doesn't match")
+        else
+          assert(expected =~ ex.message, msg || "Expected #{expected} to match #{ex.message}")
+          block.binding.eval("proc{|_|$~=_}").call($~)
+        end
+      end
     end
   end
 end

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46569


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

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