Subject: | Parsing bug for options with optional hash values |
This is perl, v5.8.7 built for i486-linux
When using an option with an optional hash value, values (not keys)
starting with a dash trigger an unexpected error:
# perl -MGetopt::Long -we "GetOptions('replace:s%');" -- --replace a=-b
Unknown option: b
#
I attach a proposed patch, it fixes the case above but I don't really
understand all the tests in this block so it might not be correct.
Subject: | getopt-long-optional-hash-value-fix.patch |
--- 5.8.7/Getopt/Long.pm.backup 2005-07-13 21:13:31.000000000 +0200
+++ 5.8.7/Getopt/Long.pm 2006-05-23 14:27:19.000000000 +0200
@@ -999,6 +999,10 @@
# A mandatory string takes anything.
return (1, $opt, $ctl, $arg, $key) if $mand;
+ # Same for optional string as a hash value
+ return (1, $opt, $ctl, $arg, $key)
+ if $ctl->[CTL_DEST] == CTL_DEST_HASH;
+
# An optional string takes almost anything.
return (1, $opt, $ctl, $arg, $key)
if defined $optarg || defined $rest;