develooper Front page | perl.perl5.porters | Postings from February 2008

[PATCH] perl -M:Foo -we 1

Thread Next
From:
Robin Barker
Date:
February 19, 2008 09:26
Subject:
[PATCH] perl -M:Foo -we 1
Message ID:
46A0F33545E63740BC7563DE59CA9C6D093A4D@exchsvr2.npl.ad.local
As discussed on london.pm, C<perl -M:DProf -we 1> does not complain.
In fact; C<perl -M:die\ GOTO -we 'goto "use";'> shows that it creates a label "use".
The attached patch forbids single ':' following -m/-M
 
Robin Barker

--- ../perl-current/perl.c	2008-02-12 13:16:57.000000000 +0000
+++ perl.c
@@ -3227,7 +3227,16 @@
 	    sv = newSVpvn(use,4);
 	    start = s;
 	    /* We allow -M'Module qw(Foo Bar)'	*/
-	    while(isALNUM(*s) || *s==':') ++s;
+	    while(isALNUM(*s) || *s==':') {
+		if( *s == ':' ) {
+		    ++s;
+		    if( *s != ':' ) 
+			Perl_croak(aTHX_
+				    "Can't use single ':' after -%c option",
+				    start[-1]);
+		}
+		++s;
+	    }
 	    end = s + strlen(s);
 	    if (*s != '=') {
 		sv_catpvn(sv, start, end - start);
--- ../perl-current/t/run/switches.t	2008-01-11 15:07:15.000000000 +0000
+++ t/run/switches.t
@@ -11,7 +11,7 @@
 
 BEGIN { require "./test.pl"; }
 
-plan(tests => 62);
+plan(tests => 64);
 
 use Config;
 
@@ -194,6 +194,17 @@
     );
     is( $r, '<swtest><foo><bar>', '-m with import parameters' );
     push @tmpfiles, $filename;
+
+    like( runperl( switches => [ '-M:swtest' ], stderr => 1,
+		   prog => 'die "oops"' ),
+	  qr/Can't use single ':' after -M option/,
+          "-M:Foo not allowed" );
+
+    like( runperl( switches => [ '-mA:B:C' ], stderr => 1,
+		   prog => 'die "oops"' ),
+	  qr/Can't use single ':' after -m option/,
+          "-M:Foo not allowed" );
+
 }
 
 # Tests for -V
 <<use-colon.patch>> 


-------------------------------------------------------------------
This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Serco House, 16 Bartley Wood Business Park,
                   Hook, Hampshire, United Kingdom  RG27 9UY
-------------------------------------------------------------------

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