[comp.lang.perl] untainting data

bjorn@sysadmin.sysadmin.com (Bjorn Satdeva) (02/15/91)

I have a problem with untainting data.  Larry examples in the manual and
book is not sufficient, as I need all alfa-numeric plus the '-'.

Currently the code looks like this (which seems to lack somewhat in 
generality :-):

------------

$ARGV[ 0 ] =~ /^(\w+)*$/;
$Addr = $1;

# The above does not work for '-' -- sigh
if ( $ARGV[ 0 ] eq 'sysadm-list' ) {
	$Addr = 'sysadm-list';
}

-----------

Any attempt on my behalf to change the regular expression to include 
the '-' only breaks it (showing that my understanding of of the regular 
expression is still somewhat lacking :-(  ).

What am I missing??

Bjorn
--
Bjorn Satdeva --  email: bjorn@sysadmin.com or uunet!sysadmin!bjorn	
/sys/admin, inc.  The Unix System Management Experts  (408) 241 3111
Send requests to the SysAdmin mailing list to sysadm-list-request@sysadmin.com

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/15/91)

In article <18@sysadmin.sysadmin.com> bjorn@sysadmin.sysadmin.com (Bjorn Satdeva) writes:
: I have a problem with untainting data.  Larry examples in the manual and
: book is not sufficient, as I need all alfa-numeric plus the '-'.
: 
: Currently the code looks like this (which seems to lack somewhat in 
: generality :-):
: 
: ------------
: 
: $ARGV[ 0 ] =~ /^(\w+)*$/;
: $Addr = $1;
: 
: # The above does not work for '-' -- sigh
: if ( $ARGV[ 0 ] eq 'sysadm-list' ) {
: 	$Addr = 'sysadm-list';
: }

I'd change that to /^([-\w]+)$/.  The - has to come first or last in [] or
else it's interpreted as a range.  (You can also use \- to hide it.)

Incidentally, Bjorn, I tried replying to your email a while ago and it
bounced.  I'd be happy to present Perl to your group.

Larry