Issue #11523 has been updated by Micha J.


Modified code example `optiontest.rb`

~~~
require 'optparse'
require 'pp'

class OptparseExample
  def self.parse(args)
    options = {}

    opt_parser = OptionParser.new do |opts|
      opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
              "Specify record separator (default \\0)") do |rs|
        options["trigger"] = "I got triggered"
      end
    end

    opt_parser.parse!(args)
    options
  end  # parse()

end  # class OptparseExample

options = OptparseExample.parse(ARGV)
pp options
pp ARGV
~~~

~~~
$ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
$ ruby optiontest.rb -i
{"trigger"=>"I got triggered"}
[]
~~~

The `-F, --irs` option is triggered with `-i`. Especially confusing as the short version is specified as `-F`


----------------------------------------
Bug #11523: optparse short options will match complete options
https://bugs.ruby-lang.org/issues/11523#change-54246

* Author: Micha J
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
In short, if I define an option like `"-F", "--irs [OCTAL]"`, `-i` will match this option, although the short version is defined as `-F`.

----

In long, this can be quite troublesome:

See the provided example

http://ruby-doc.org/stdlib-2.2.0/libdoc/optparse/rdoc/OptionParser.html

and change or remove the `"-i", "--inplace [EXTENSION]"` option for something else than `i`:

Now, the -i will still match, but the other option `"-F", "--irs [OCTAL]"`!

In a more complete stack this resulted in a hard to find error. Also, to fix this (and raise the required error) you need to check the ARGV directly which renders optparse a bit less useful.




-- 
https://bugs.ruby-lang.org/