Bug #8865
closedOptionParser acceptable bugs
Description
I have found a few bugs in OptionParser's accept feature:
Hexadecimal and binary numbers are not properly supported for Integer
OptionParser::DecimalInteger, OptionParser::OctalInteger and OptionParser::DecimalNumeric convert invalid input to 0 or nil instead of raising InvalidArgument.
The attached patch fixes the validation regular expression for handling binary and hexadecimal arguments and adds verification for DecimalInteger, OctalInteger and DecimalNumeric
Files
Updated by drbrain (Eric Hodel) about 11 years ago
Updated with patch 2 that includes tests
Updated by drbrain (Eric Hodel) about 11 years ago
Here is patch 3 that uses end-of-string anchoring to ensure the entire number is bad.
Updated by drbrain (Eric Hodel) about 11 years ago
- Assignee changed from nobu (Nobuyoshi Nakada) to drbrain (Eric Hodel)
From #ruby-core IRC:
19:46 nokada: drbrain: seems fine, and add tests 1234xyz fails, plz
Updated by drbrain (Eric Hodel) about 11 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r42844.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
-
lib/optparse.rb: The Integer acceptable now allows binary and
hexadecimal numbers per the documentation. [ruby-trunk - Bug #8865]DecimalInteger, OctalInteger, DecimalNumeric now validate their input
before converting to a number. [ruby-trunk - Bug #8865] -
test/optparse/test_acceptable.rb: Tests for the above, tests for all
numeric acceptables for existing behavior.
Updated by usa (Usaku NAKAMURA) over 10 years ago
- Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED to 1.9.3: DONE, 2.0.0: REQUIRED
backported into ruby_1_9_3 at r44935.
Updated by nagachika (Tomoyuki Chikanaga) over 10 years ago
- Backport changed from 1.9.3: DONE, 2.0.0: REQUIRED to 1.9.3: DONE, 2.0.0: DONE
r42844 and r42845 were backported to ruby_2_0_0 at r45050.