in reply to Re: subparseform.lib
Are you aware that the semicolon ';' is an alternate delimeter for name/value pairs? Also, what happens if there is a problem with $ENV{'CONTENT_LENGTH'} not matching the actual data length? You need to test for that or risk occassionally having corrupted data. Also, you may also want a test if the read is successful.if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer);
I see where you are going with removing ASCII zero and "dangerous" characters, but this limits the flexibility of your code. What if someone really needs these characters to be uploaded? What are their options?## REMOVE poison NULL $key =~ s/\0//g; $value =~ s/\0//g; ## Clean characters to remove weird stuff my $allowedCHARS = 'a-zA-Z0-9\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\ +;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~'; $key =~ s/[^$allowedCHARS]//gi; $value =~ s/[^$allowedCHARS]//gi;
Aaagh!!!! I get tired of seeing this. The real purpose of this is to strip out SSIs from incoming data, in case this data gets written out to a Weg page that someone else might call up. The reality is, it's a horrible regex (dot star, alternation on single characters, and will slurp up multiple SSI's or HTML Comments and anything in between. Plus, what if someone wants HTML comments or SSI's to be submitted? Again, you have the non-orthogonal code issue. See list above.$key =~s/<!--(.|\n)*-->//g;
No. What if someone wants the extra whitespace? Non-orthogonal.###=== Begin Cosmetic/Functionality addition ======== ## REMOVE LEADING BLANKS $key =~ s/^\s*//; ## REMOVE TRAILING BLANKS $key =~ s/\s*$//; ###=== End Cosmetic/Functionality addition ==========
The intent of your code is to have them do something like this:if ($formdata{$key}) { $formdata{$key} .= ", $value"; } else { $formdata{$key} = $value; }
Hmmm... what happens if some enters a value with a comma and space? That's right, they think they have an extra value.my @values = split /, /, $formdata{ $somekey };
Of course, your code doesn't handle file uploads, either, but that's a whole 'nother ball of wax.
I'm sorry, but this is terrible cargo-cult code. Your heart is in the right place, but this code is terrible.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid - cargo-cult CGI) Re: Re: subparseform.lib
by Xxaxx (Monk) on Apr 28, 2001 at 08:38 UTC | |
by Ovid (Cardinal) on Apr 28, 2001 at 19:55 UTC | |
by AgentM (Curate) on Apr 28, 2001 at 08:47 UTC |