Front page | perl.perl5.porters |
Postings from August 2008
Re: [perl #30660][PATCH] Repeated spaces on shebang line stops option parsing
Thread Previous
From:
Nicholas Clark
Date:
August 28, 2008 06:15
Subject:
Re: [perl #30660][PATCH] Repeated spaces on shebang line stops option parsing
Message ID:
20080828131441.GO75181@plum.flirble.org
On Tue, Aug 26, 2008 at 09:16:16AM +0200, H.Merijn Brand wrote:
> On Tue, 26 Aug 2008 08:43:55 +0200, Renée Bäcker
> <renee.baecker@smart-websolutions.de> wrote:
> > > Do you have an example of what this is solving? It seems a logical change to
> > > make, but I'm guessing as to what the problem is.
> > >
> >
> > Attached is a small script. Without this patch it just recognizes the -s
> > switch but not the -w switch.
Thanks. I used a variant in my test.
> > > That can be
> > >
> > > while( isSPACE(*s) )
> > > ++s;
> > >
> > > because isSPACE('\0') is going to be false.
> > >
> > >
> > > But is using isSPACE() correct, given that '\r', '\n' and particularly '\t'
> > > are handled differently in code below?
> > > (And no, I'm not intimately familiar with what it is doing, or why)
> > >
> >
> > So this should be rewritten as
> >
> > while( *s && ( s[0] == ' ' ) )
> > ++s;
>
> That is just one test too many, as it is effectively the same as
>
> while (*s == ' ') s++;
>
> if *s == (char)0, *s == ' ' will be false
> If you also want to allow tabs,
>
> while (*s == ' ' || *s == '\t') s++;
Tabs are handled differently in the code below
case '\n':
case '\t':
break;
so it didn't seem logical to include them here.
I applied the appended change.
Nicholas Clark
Change 34234 by nicholas@nicholas-saigo on 2008/08/28 13:11:44
Fix #30660: Repeated spaces on shebang line stops option parsing
From a patch and test sent by Renée Bäcker in
<48B271A3.80808@smart-websolutions.de>
Affected files ...
... //depot/perl/perl.c#874 edit
... //depot/perl/t/run/switches.t#28 edit
Differences ...
==== //depot/perl/perl.c#874 (text) ====
@@ -3431,8 +3431,10 @@
return s;
case '*':
case ' ':
- if (s[1] == '-') /* Additional switches on #! line. */
- return s+2;
+ while( *s == ' ' )
+ ++s;
+ if (s[0] == '-') /* Additional switches on #! line. */
+ return s+1;
break;
case '-':
case 0:
==== //depot/perl/t/run/switches.t#28 (text) ====
@@ -11,7 +11,7 @@
BEGIN { require "./test.pl"; }
-plan(tests => 69);
+plan(tests => 70);
use Config;
@@ -350,3 +350,19 @@
stdin => 'zomtek',
);
is( $r, "affe\n", '-E works outside of the block created by -n' );
+
+# RT #30660
+
+$filename = tempfile();
+SKIP: {
+ open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
+ print $f <<'SWTEST';
+#!perl -w -iok
+print "$^I\n";
+SWTEST
+ close $f or die "Could not close: $!";
+ $r = runperl(
+ progfile => $filename,
+ );
+ like( $r, qr/ok/, 'Spaces on the #! line (#30660)' );
+}
Thread Previous