Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find2perl mistranslates fileglob ? to regex .? #12130

Closed
p5pRT opened this issue May 23, 2012 · 6 comments
Closed

find2perl mistranslates fileglob ? to regex .? #12130

p5pRT opened this issue May 23, 2012 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented May 23, 2012

Migrated from rt.perl.org#113054 (status was 'resolved')

Searchable as RT113054$

@p5pRT
Copy link
Author

p5pRT commented May 23, 2012

From chall0@gmail.com

Created by chall0@gmail.com

When find2perl attempts to convert fileglob patterns to regular expressions, it fails to do the right thing for the ? character. The resulting regex uses .? instead of just . and thus incorrectly matches an empty substring. Test case​:

$ touch ab axb ayb
$ find -name a\?b
./ayb
./axb
$ find2perl -name a\?b|perl
./ayb
./axb
./ab
$

The following patch seems to fix it for me​:

Inline Patch
--- find2perl.orig      2012-03-06 19:36:39.000000000 +0000
+++ find2perl   2012-05-23 12:21:04.976166972 +0100
@@ -648,7 +648,8 @@
 sub fileglob_to_re ($) {
     my $x = shift;
     $x =~ s#([./^\$()+])#\\$1#g;
-    $x =~ s#([?*])#.$1#g;
+    $x =~ s#\*#.*#g;
+    $x =~ s#\?#.#g;
     "^$x\\z";
 }
Perl Info

Flags:
    category=utilities
    severity=low

Site configuration information for perl 5.12.4:

Configured by Gentoo at Tue Mar  6 19:24:52 GMT 2012.

Summary of my perl5 (revision 5 version 12 subversion 4) configuration:
   
  Platform:
    osname=linux, osvers=3.2.5-gentoo, archname=i686-linux-thread-multi
    uname='linux koko 3.2.5-gentoo #1 smp tue feb 14 10:48:29 gmt 2012 i686 intel(r) celeron(r) cpu e1200 @ 1.60ghz genuineintel gnulinux '
    config_args='-des -Duseshrplib -Darchname=i686-linux-thread -Dcc=i686-pc-linux-gnu-gcc -Doptimize=-O2 -march=native -ggdb -pipe -Dldflags=-Wl,-O1 -Wl,--as-needed -Dprefix=/usr -Dinstallprefix=/usr -Dsiteprefix=/usr -Dvendorprefix=/usr -Dscriptdir=/usr/bin -Dprivlib=/usr/lib/perl5/5.12.4 -Darchlib=/usr/lib/perl5/5.12.4/i686-linux-thread-multi -Dsitelib=/usr/lib/perl5/site_perl/5.12.4 -Dsitearch=/usr/lib/perl5/site_perl/5.12.4/i686-linux-thread-multi -Dvendorlib=/usr/lib/perl5/vendor_perl/5.12.4 -Dvendorarch=/usr/lib/perl5/vendor_perl/5.12.4/i686-linux-thread-multi -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/share/man/man1 -Dsiteman3dir=/usr/share/man/man3 -Dvendorman1dir=/usr/share/man/man1 -Dvendorman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3pm -Dlibperl=libperl.so.5.12.4 -Dlocincpth=/usr/include  -Dglibpth=/lib /usr/lib  -Duselargefiles -Dd_semctl_semun -Dcf_by=Gentoo -Dmyhostname=localhost -Dperladmin=root@localhost -Dinstallusrbinperl=n -Ud_csh -Uusenm -Di_ndbm -Di_gdbm -Di_db -Dusethreads -DDEBUGGING=-g -Dinc_version_list=5.12.3/i686-linux-thread-multi 5.12.3 5.12.2/i686-linux-thread-multi 5.12.2 5.12.1/i686-linux-thread-multi 5.12.1 5.12.0/i686-linux-thread-multi 5.12.0  -Dnoextensions=ODBM_File'
    hint=recommended, useposix=true, d_sigaction=define
    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='i686-pc-linux-gnu-gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=native -ggdb -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe'
    ccversion='', gccversion='4.5.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='i686-pc-linux-gnu-gcc', ldflags ='-Wl,-O1 -Wl,--as-needed'
    libpth=/lib/../lib /usr/lib/../lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.14.1.so, so=so, useshrplib=true, libperl=libperl.so.5.12.4
    gnulibc_version='2.14.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -march=native -ggdb -pipe -Wl,-O1 -Wl,--as-needed'

Locally applied patches:
    0001-gentoo_MakeMaker-RUNPATH.diff
    0002-gentoo_config_over.diff
    0003-gentoo_cpan_definstalldirs.diff
    0004-gentoo_cpanplus_definstalldirs.diff
    0005-gentoo_create-libperl-soname.diff
    0006-gentoo_MakeMaker-delete_packlist.diff
    0007-fixes_8d66b3f9_h2hp_fix.diff
    0008-fixes_f178b03b_h2ph_using_deprecated_goto.diff
    0009-gentoo_mod-paths.diff
    0010-gentoo_enc2xs.diff
    0011-gentoo_IO-Compress_AutoLoader_dropped_from_Compress-Zlib.diff
    0012-gentoo_drop-fstack-protector.diff


@INC for perl 5.12.4:
    /etc/perl
    /usr/lib/perl5/site_perl/5.12.4/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.12.4
    /usr/lib/perl5/vendor_perl/5.12.4/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.12.4
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.12.3/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.12.3
    /usr/lib/perl5/vendor_perl/5.12.2
    /usr/lib/perl5/vendor_perl/5.12.1
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.12.4/i686-linux-thread-multi
    /usr/lib/perl5/5.12.4
    /usr/local/lib/site_perl
    .


Environment for perl 5.12.4:
    HOME=/root
    LANG=en_GB.utf8
    LANGUAGE (unset)
    LC_CTYPE=en_GB.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.6.3:/usr/i486-pc-linux-gnu/gcc-bin/4.1.2:/opt/Citrix/ICAClient:/opt/stuffit/bin:/usr/lib/subversion/bin:/opt/cuda/bin:/var/qmail/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented May 24, 2012

From @jkeenan

On Wed May 23 04​:23​:48 2012, chall0@​gmail.com wrote​:

This is a bug report for perl from chall0@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.12.4.

-----------------------------------------------------------------
[Please describe your issue here]

When find2perl attempts to convert fileglob patterns to regular
expressions, it fails to do the right thing for the ? character.
The resulting regex uses .? instead of just . and thus incorrectly
matches an empty substring. Test case​:

$ touch ab axb ayb
$ find -name a\?b
./ayb
./axb
$ find2perl -name a\?b|perl
./ayb
./axb
./ab
$

The following patch seems to fix it for me​:

--- find2perl.orig 2012-03-06 19​:36​:39.000000000 +0000
+++ find2perl 2012-05-23 12​:21​:04.976166972 +0100
@​@​ -648,7 +648,8 @​@​
sub fileglob_to_re ($) {
my $x = shift;
$x =~ s#([./^\$()+])#\\$1#g;
- $x =~ s#([?*])#.$1#g;
+ $x =~ s#\*#.*#g;
+ $x =~ s#\?#.#g;
"^$x\\z";
}

Reviewing this RT, I had occasion to ack blead for 'find2perl'. I
noticed that there do not appear to be any test files devoted to this
program.

Is that correct? If so, would we be able to write tests for 'find2perl'
-- including a test that would demonstrate the fix in this patch -- in a
way that could accommodate many different shells?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented May 24, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 14, 2013

From @tonycoz

On Wed May 23 17​:47​:08 2012, jkeenan wrote​:

Reviewing this RT, I had occasion to ack blead for 'find2perl'. I
noticed that there do not appear to be any test files devoted to this
program.

Is that correct? If so, would we be able to write tests for 'find2perl'
-- including a test that would demonstrate the fix in this patch -- in a
way that could accommodate many different shells?

I've added (currently in smoke-me/tonyc/find2perl) some basic tests for
find2perl, including a test and the fix for the problem in this ticket.

Currently it compares the results against find(1) and restricts the
platforms where testing is done to platforms with a vaguely sane find(1)
(eg. not Win32)

If it smokes ok I'll push it to blead.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 21, 2013

From @tonycoz

On Wed May 23 17​:47​:08 2012, jkeenan wrote​:

Reviewing this RT, I had occasion to ack blead for 'find2perl'. I
noticed that there do not appear to be any test files devoted to this
program.

Is that correct? If so, would we be able to write tests for 'find2perl'
-- including a test that would demonstrate the fix in this patch -- in a
way that could accommodate many different shells?

I've added tests in bdbb33c, structured
so anyone with a reasonable knowledge of perl and find can add new tests.

I fixed the ? mis-mapping in bea9788.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 21, 2013

@tonycoz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant