Skip Menu |

This queue is for tickets about the Getopt-Euclid CPAN distribution.

Report information
The Basics
Id: 76728
Status: resolved
Priority: 0/
Queue: Getopt-Euclid

People
Owner: Nobody in particular
Requestors: inky [...] inera.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Getopt::Euclid bug: it chokes when one option value is a substring of another option value
Date: Fri, 20 Apr 2012 20:01:58 +0400
To: bug-getopt-euclid [...] rt.cpan.org
From: Igor Kleshchevich <inky [...] inera.com>
Hello dear Getopt::Euclid hackers! :-) I've encountered what appears to be a serious bug in Getopt::Euclid. (It's possible that I'm doing something wrong, of course, but if so, I cannot determine what it is) It seems that when Getopt::Euclid is used to define CL interface for a Pelr script, and when of two consecutive parameters passed to that script first is a substring of a second, Getopt::Euclid chokes on it. ***************************************************** One example is the attached file Test.pl. It has the following in its POD section: =item -compare <old_dir> <new_dir> Specify a pair of directory paths to compare: =for Euclid: old_dir.type: string new_dir.type: string If this script is called like this: Perl Test.pl -compare AAA BBBB or like this: Perl Test.pl -compare AAA AA it works just fine. However, if the first value is a substring of the second value, it chocks: Perl Test.pl -compare AAA AAAA Unknown argument: AAAA (Try this for usage help : Test.pl --help) (Try this for full manual: Test.pl --man ) ***************************************************** 2. Another example is the attached file Test1.pl It has the following in its POD section: =item -old <old> Specify old string =for Euclid: old.type: string =item -new <new> Specify new string =for Euclid: new.type: string Again, if I run Perl Test1.pl -old AAA -new BB or Perl Test1.pl -old AAA -new AA it works just fine. But if I run Perl Test1.pl -old AAA -new AAAA it chocks with a somewhat different message: Unknown argument: -new AAAA (Try this for usage help : Test1.pl --help) (Try this for full manual: Test1.pl --man ) ***************************************************** I'm running ActiveState distribution of Perl 5.10 on Windows XP. Getopt::Euclid version 0.3.5 If it would help I can easily test on Perl 5.12 and 5.14, and on Windows 7. I hope this is relevant, and will help to improve great Getopt::Euclid module! Please let me know if I can help further. Of course I would like to know what happens to this bug. Thank you! Igor Below are details about my Perl installation in case they may be relevant: ****************************************************** Here is the output of "Perl --version": This is perl, v5.10.1 built for MSWin32-x86-multi-thread (with 2 registered patches, see perl -V for more detail) Copyright 1987-2009, Larry Wall Binary build 1006 [291086] provided by ActiveState http://www.ActiveState.com Built Aug 24 2009 13:48:26 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. ****************************************************** Here is the output of "Perl -V": Summary of my perl5 (revision 5 version 10 subversion 1) configuration: Platform: osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE - DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IM PLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX', optimize='-MD -Zi -DNDEBUG -O1', cppflags='-DWIN32' ccversion='12.00.8804', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksi ze=8 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"C: \Perl\lib\CORE" -machine:x86' libpth=\lib libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32 .lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_ 32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comd lg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf - libpath:"C:\Perl\lib\CORE" -machine:x86' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_SITECUSTOMIZE Locally applied patches: ActivePerl Build 1006 [291086] 32728 64-bit fix for Time::Local Built under MSWin32 Compiled at Aug 24 2009 13:48:26 @INC: C:/Perl/site/lib C:/Perl/lib .

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Hi Igor, Thanks for your concise test cases that I could use to reproduce and confirm the bug. This issue probably has to do with the regular expressions that Getopt::Euclid uses to parse command-line argument. I will have to investigate deeper when I have more time. Regards, Florent
From: james.f.hester [...] gmail.com
Florent, I was having the same issue as Igor, and tracked it down to the $no_esc_ws variable in _convert_to_regex. Changing its value from '(?!\0|\1)' to '(?!\0)' allowed the program to pass my new tests as well as all of the other tests in the distribution. I have attached a patch which includes the change, as well as the additional tests for this issue. -Jim Hester On Thu Apr 26 01:19:52 2012, FANGLY wrote: Show quoted text
> Hi Igor, > > Thanks for your concise test cases that I could use to reproduce and > confirm the bug. This issue probably has to do with the regular > expressions that Getopt::Euclid uses to parse command-line argument. I > will have to investigate deeper when I have more time. > > Regards, > > Florent
Subject: 76728.patch
diff --git a/lib/Getopt/Euclid.pm b/lib/Getopt/Euclid.pm index 84eb5ad..4ae3011 100644 --- a/lib/Getopt/Euclid.pm +++ b/lib/Getopt/Euclid.pm @@ -974,7 +974,7 @@ sub _convert_to_regex { my ($args_ref) = @_; # Regexp to capture the start of a new argument - my $no_esc_ws = '(?!\0|\1)'; # no escaped whitespaces + my $no_esc_ws = '(?!\0)'; # no escaped whitespaces my @arg_variants; while ( my ($arg_name, $arg_specs) = each %{$args_ref} ) { push @arg_variants, @{$arg_specs->{variants}}; diff --git a/t/substr1.t b/t/substr1.t new file mode 100644 index 0000000..bccd078 --- /dev/null +++ b/t/substr1.t @@ -0,0 +1,26 @@ +BEGIN { + @ARGV = ( + '-i', 'test', + '-o', 'test2', + ); +} + +use Getopt::Euclid; +use Test::More 'no_plan'; + +is $ARGV{'-i'}, 'test' => 'Got expected value for -i'; +is $ARGV{'-o'}, 'test2' => 'Got expected value for -o'; + +__END__ + +=head1 NAME + +substr.pl - short description + +=head1 REQUIRED ARGUMENTS + +=head1 OPTIONS + +=item -o <o> + +=item -i <i> diff --git a/t/substr2.t b/t/substr2.t new file mode 100644 index 0000000..6005802 --- /dev/null +++ b/t/substr2.t @@ -0,0 +1,26 @@ +BEGIN { + @ARGV = ( + '-o', 'test', + '-i', 'test2', + ); +} + +use Getopt::Euclid; +use Test::More 'no_plan'; + +is $ARGV{'-i'}, 'test2' => 'Got expected value for -i'; +is $ARGV{'-o'}, 'test' => 'Got expected value for -o'; + +__END__ + +=head1 NAME + +substr.pl - short description + +=head1 REQUIRED ARGUMENTS + +=head1 OPTIONS + +=item -o <o> + +=item -i <i>
Hi Jim and thanks very much for the patch. It worked very well on your test cases and mine as well. Have a look at CPAN for Getopt::Euclid version 0.4.0. Florent