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

ruby-changes:47414

From: usa <ko1@a...>
Date: Wed, 9 Aug 2017 16:56:58 +0900 (JST)
Subject: [ruby-changes:47414] usa:r59530 (ruby_2_3): merge revision(s) 59312: [Backport #13739]

usa	2017-08-09 16:56:52 +0900 (Wed, 09 Aug 2017)

  New Revision: 59530

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

  Log:
    merge revision(s) 59312: [Backport #13739]
    
    optparse.rb: get rid of eval
    
    * lib/optparse.rb: try Float() and Integer() instead of eval,
      which does too much things.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/lib/optparse.rb
    branches/ruby_2_3/test/optparse/test_acceptable.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/lib/optparse.rb
===================================================================
--- ruby_2_3/lib/optparse.rb	(revision 59529)
+++ ruby_2_3/lib/optparse.rb	(revision 59530)
@@ -1836,7 +1836,7 @@ XXX https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/optparse.rb#L1836
   #
   # Float number format, and converts to Float.
   #
-  float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
+  float = "(?:#{decimal}(?=(.)?)(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
   floatpat = %r"\A[-+]?#{float}\z"io
   accept(Float, floatpat) {|s,| s.to_f if s}
 
@@ -1845,11 +1845,13 @@ XXX https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/optparse.rb#L1845
   # for float format, and Rational for rational format.
   #
   real = "[-+]?(?:#{octal}|#{float})"
-  accept(Numeric, /\A(#{real})(?:\/(#{real}))?\z/io) {|s, d, n|
+  accept(Numeric, /\A(#{real})(?:\/(#{real}))?\z/io) {|s, d, f, n,|
     if n
       Rational(d, n)
-    elsif s
-      eval(s)
+    elsif f
+      Float(s)
+    else
+      Integer(s)
     end
   }
 
@@ -1883,10 +1885,14 @@ XXX https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/optparse.rb#L1885
   # integer format, Float for float format.
   #
   DecimalNumeric = floatpat     # decimal integer is allowed as float also.
-  accept(DecimalNumeric, floatpat) {|s,|
+  accept(DecimalNumeric, floatpat) {|s, f|
     begin
-      eval(s)
-    rescue SyntaxError
+      if f
+        Float(s)
+      else
+        Integer(s)
+      end
+    rescue ArgumentError
       raise OptionParser::InvalidArgument, s
     end if s
   }
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 59529)
+++ ruby_2_3/version.h	(revision 59530)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.5"
-#define RUBY_RELEASE_DATE "2017-07-07"
-#define RUBY_PATCHLEVEL 342
+#define RUBY_RELEASE_DATE "2017-08-09"
+#define RUBY_PATCHLEVEL 343
 
 #define RUBY_RELEASE_YEAR 2017
-#define RUBY_RELEASE_MONTH 7
-#define RUBY_RELEASE_DAY 7
+#define RUBY_RELEASE_MONTH 8
+#define RUBY_RELEASE_DAY 9
 
 #include "ruby/version.h"
 
Index: ruby_2_3/test/optparse/test_acceptable.rb
===================================================================
--- ruby_2_3/test/optparse/test_acceptable.rb	(revision 59529)
+++ ruby_2_3/test/optparse/test_acceptable.rb	(revision 59530)
@@ -85,6 +85,9 @@ class TestOptionParser::Acceptable < Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/optparse/test_acceptable.rb#L85
     assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 1/2")})
     assert_equal(Rational(1, 2), @numeric)
 
+    assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 010")})
+    assert_equal(8, @numeric)
+
     assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 1.2/2.3")})
     assert_equal(Rational(12, 23), @numeric)
 
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 59529)
+++ ruby_2_3	(revision 59530)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r59312

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

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