Project

General

Profile

Actions

Bug #8865

closed

OptionParser acceptable bugs

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

Status:
Closed
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


Files

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

Updated by drbrain (Eric Hodel) over 10 years ago

Updated with patch 2 that includes tests

Updated by drbrain (Eric Hodel) over 10 years ago

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

Updated by drbrain (Eric Hodel) over 10 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

Actions #4

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0