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

ruby-changes:47158

From: nobu <ko1@a...>
Date: Thu, 6 Jul 2017 20:49:10 +0900 (JST)
Subject: [ruby-changes:47158] nobu:r59273 (trunk): Fix DecimalInteger converting to octal bug

nobu	2017-07-06 20:49:03 +0900 (Thu, 06 Jul 2017)

  New Revision: 59273

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

  Log:
    Fix DecimalInteger converting to octal bug
    
    Previously if the input started with a '0' then it will be converted
    as octal even though it has been specified as a decimal. This commit
    forces the number to be interpreted as a decimal.
    
    [ruby-core:81927] [Bug #13722] [Fix GH-1665]
    Author:    william <william.mccumstie@o...>

  Modified files:
    trunk/lib/optparse.rb
    trunk/test/optparse/test_acceptable.rb
Index: lib/optparse.rb
===================================================================
--- lib/optparse.rb	(revision 59272)
+++ lib/optparse.rb	(revision 59273)
@@ -1865,7 +1865,7 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1865
   DecimalInteger = /\A[-+]?#{decimal}\z/io
   accept(DecimalInteger, DecimalInteger) {|s,|
     begin
-      Integer(s)
+      Integer(s, 10)
     rescue ArgumentError
       raise OptionParser::InvalidArgument, s
     end if s
Index: test/optparse/test_acceptable.rb
===================================================================
--- test/optparse/test_acceptable.rb	(revision 59272)
+++ test/optparse/test_acceptable.rb	(revision 59273)
@@ -108,16 +108,16 @@ class TestOptionParser::Acceptable < Tes https://github.com/ruby/ruby/blob/trunk/test/optparse/test_acceptable.rb#L108
     assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 10")})
     assert_equal(10, @decimal_integer)
 
+    assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 010")})
+    assert_equal(10, @decimal_integer)
+
+    assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 09")})
+    assert_equal(9, @decimal_integer)
+
     assert_raise(OptionParser::InvalidArgument) do
       @opt.parse!(%w"--decimal-integer 0b1")
     end
 
-    e = assert_raise(OptionParser::InvalidArgument) do
-      @opt.parse!(%w"--decimal-integer 09")
-    end
-
-    assert_equal("invalid argument: --decimal-integer 09", e.message)
-
     assert_raise(OptionParser::InvalidArgument) do
       @opt.parse!(%w"--decimal-integer x")
     end

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

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