aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-06 11:49:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-06 11:49:03 +0000
commitcf2a12c81e5282c192f9f0a63b3afff6806df223 (patch)
treec7c4b520d2901ee3ae854b2662a0944a69faa887
parenteebd8625298327f5ef6d22030633039723fd6fc6 (diff)
downloadruby-cf2a12c81e5282c192f9f0a63b3afff6806df223.tar.gz
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@outlook.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/optparse.rb2
-rw-r--r--test/optparse/test_acceptable.rb12
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index d887e2f98d..b4c44545bb 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1865,7 +1865,7 @@ XXX
DecimalInteger = /\A[-+]?#{decimal}\z/io
accept(DecimalInteger, DecimalInteger) {|s,|
begin
- Integer(s)
+ Integer(s, 10)
rescue ArgumentError
raise OptionParser::InvalidArgument, s
end if s
diff --git a/test/optparse/test_acceptable.rb b/test/optparse/test_acceptable.rb
index 0c7590bae3..dd38f8ec7a 100644
--- a/test/optparse/test_acceptable.rb
+++ b/test/optparse/test_acceptable.rb
@@ -108,16 +108,16 @@ class TestOptionParser::Acceptable < TestOptionParser
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