ybiC has asked for the wisdom of the Perl Monks concerning the following question:
Two questions:
1 - How to add site home (index.pl?page=home) as the default if *no* param given, but still fail if *bad* param given?
2 - Untainting regexp that will reject if non-word character anywhere in provided param, not just if non-word char is first character.
All suggestions welcome and appreciated.
cheers,
Don
striving for Perl Adept
(it's pronounced "why-bick")
# Read in URL file query and untaint # one or more word characters if ($query = param('page') =~ /(\w+)/) { $urlist = $1; } else {die "Please request pages by alphanumeric name only. You might find what you're looking for by starting at site home of http://host.dom/index.pl?page=home\n"; } # Build array of urlist files # Confirm that supplied param is valid file opendir DIR, "$confdir/"; my @files = grep { $_ ne '.' && $_ ne '..' && } readdir DIR; closedir DIR; unless (grep{$_ eq $urlist} @files) { die "You requested a page that does not exist. You might find what you're looking for by starting at site home of http://host.dom/index.pl?page=home\n"; } # read lists of page URLs from external file # loop through lists, parsing for HTML::Template use unless (my $return = do "$confdir/$urlist") { die "Cannot parse $urlist: $@" if $@; die "Cannot do $urlist: $!" unless defined $return; die "Cannot run $urlist" unless $return; } for (my $i = 0; $i < $#url_array; $i+=2) { my($loop, $aref) = @url_array[$i, $i+1]; my @vars; for (my $j = 0; $j < $#{$aref}; $j+=2) { my($name, $url) = @{$aref}[$j, $j+1]; push @vars, { name => $name, url => $url }; } $template->param($loop, [ @vars ]); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: Default CGI.pm param() if none provided?
by Ovid (Cardinal) on Dec 28, 2000 at 04:22 UTC | |
by chromatic (Archbishop) on Dec 28, 2000 at 04:44 UTC | |
by ybiC (Prior) on Dec 28, 2000 at 07:56 UTC | |
by ybiC (Prior) on Dec 28, 2000 at 04:33 UTC | |
|
Re: Default CGI.pm param() if none provided?
by davorg (Chancellor) on Dec 28, 2000 at 04:20 UTC | |
|
Re: Default CGI.pm param() if none provided?
by a (Friar) on Dec 28, 2000 at 10:00 UTC |