mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
06a3a10acf
commit
8ddf0263bb
2 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue