Bug #8865

OptionParser acceptable bugs

Added by Eric Hodel 8 months ago. Updated 2 months ago.

[ruby-core:57024]
Status:Closed
Priority:Normal
Assignee:Eric Hodel
Category:lib
Target version:-
ruby -v:- Backport:1.9.3: DONE, 2.0.0: DONE

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

optparse.rb.accept.patch Magnifier (1.63 KB) Eric Hodel, 09/05/2013 06:00 AM

optparse.rb.accept.2.patch Magnifier (6.85 KB) Eric Hodel, 09/05/2013 09:20 AM

optparse.rb.accept.3.patch Magnifier (7.77 KB) Eric Hodel, 09/05/2013 09:47 AM

Associated revisions

Revision 42844
Added by Eric Hodel 8 months ago

  • 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.

History

#1 Updated by Eric Hodel 8 months ago

Updated with patch 2 that includes tests

#2 Updated by Eric Hodel 8 months ago

Here is patch 3 that uses end-of-string anchoring to ensure the entire number is bad.

#3 Updated by Eric Hodel 8 months ago

  • Assignee changed from Nobuyoshi Nakada to Eric Hodel

From #ruby-core IRC:

19:46 nokada: drbrain: seems fine, and add tests 1234xyz fails, plz

#4 Updated by Eric Hodel 8 months 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.

#5 Updated by Usaku NAKAMURA 2 months ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED to 1.9.3: DONE, 2.0.0: REQUIRED

backported into ruby19_3 at r44935.

#6 Updated by Tomoyuki Chikanaga 2 months 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 ruby20_0 at r45050.

Also available in: Atom PDF