develooper Front page | perl.perl5.porters | Postings from May 2012

[perl #113054] find2perl mistranslates fileglob ? to regex .?

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
May 23, 2012 17:47
Subject:
[perl #113054] find2perl mistranslates fileglob ? to regex .?
Message ID:
rt-3.6.HEAD-7788-1337820428-262.113054-15-0@perl.org
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

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=113054

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About