Project

General

Profile

Bug #8865

OptionParser acceptable bugs

Added by drbrain (Eric Hodel) about 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
-
[ruby-core:57024]

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 (1.63 KB) optparse.rb.accept.patch drbrain (Eric Hodel), 09/05/2013 06:00 AM
optparse.rb.accept.2.patch (6.85 KB) optparse.rb.accept.2.patch drbrain (Eric Hodel), 09/05/2013 09:20 AM
optparse.rb.accept.3.patch (7.77 KB) optparse.rb.accept.3.patch drbrain (Eric Hodel), 09/05/2013 09:47 AM

Associated revisions

Revision 42844
Added by drbrain (Eric Hodel) about 4 years 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.

Revision 42844
Added by drbrain (Eric Hodel) about 4 years 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.

Revision 42844
Added by drbrain (Eric Hodel) about 4 years 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.

Revision 42844
Added by drbrain (Eric Hodel) about 4 years 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 [ruby-core:57029] Updated by drbrain (Eric Hodel) about 4 years ago

Updated with patch 2 that includes tests

#2 [ruby-core:57030] Updated by drbrain (Eric Hodel) about 4 years ago

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

#3 [ruby-core:57034] Updated by drbrain (Eric Hodel) about 4 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

#4 Updated by drbrain (Eric Hodel) about 4 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.

#5 [ruby-core:60702] Updated by usa (Usaku NAKAMURA) over 3 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.

#6 [ruby-core:60871] Updated by nagachika (Tomoyuki Chikanaga) over 3 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.

Also available in: Atom PDF