summaryrefslogtreecommitdiffstats
path: root/CGI.pl
diff options
context:
space:
mode:
authormyk%mozilla.org <>2001-10-31 08:42:21 +0100
committermyk%mozilla.org <>2001-10-31 08:42:21 +0100
commit2b77f7466f51a1248e7cb8af45f41d812ddef8f8 (patch)
treecad615fdf1d42f5e01f6d855ff326575fd872aaa /CGI.pl
parent5fd4cf4381e34c57a6b1dcc7ea3fa57d8f42d0cf (diff)
downloadbugzilla-2b77f7466f51a1248e7cb8af45f41d812ddef8f8.tar.gz
bugzilla-2b77f7466f51a1248e7cb8af45f41d812ddef8f8.tar.xz
Fix for bug 98602: re-implementation of "create attachment" page.
Patch by Myk Melez <myk@mozilla.org>. r=gerv@mozilla.org,jake@acutex.net
Diffstat (limited to 'CGI.pl')
-rw-r--r--CGI.pl76
1 files changed, 46 insertions, 30 deletions
diff --git a/CGI.pl b/CGI.pl
index 793e2eb07..593079c4a 100644
--- a/CGI.pl
+++ b/CGI.pl
@@ -42,7 +42,6 @@ use strict;
sub CGI_pl_sillyness {
my $zz;
- $zz = %::FILENAME;
$zz = %::MFORM;
$zz = %::dontchange;
}
@@ -148,46 +147,63 @@ sub ProcessFormFields {
sub ProcessMultipartFormFields {
- my ($boundary) = (@_);
- $boundary =~ s/^-*//;
- my $remaining = $ENV{"CONTENT_LENGTH"};
+ my ($boundary) = @_;
+
+ # Initialize variables that store whether or not we are parsing a header,
+ # the name of the part we are parsing, and its value (which is incomplete
+ # until we finish parsing the part).
my $inheader = 1;
- my $itemname = "";
-# open(DEBUG, ">debug") || die "Can't open debugging thing";
-# print DEBUG "Boundary is '$boundary'\n";
+ my $fieldname = "";
+ my $fieldvalue = "";
+
+ # Read the input stream line by line and parse it into a series of parts,
+ # each one containing a single form field and its value and each one
+ # separated from the next by the value of $boundary.
+ my $remaining = $ENV{"CONTENT_LENGTH"};
while ($remaining > 0 && ($_ = <STDIN>)) {
$remaining -= length($_);
-# print DEBUG "< $_";
+
+ # If the current input line is a boundary line, save the previous
+ # form value and reset the storage variables.
if ($_ =~ m/^-*$boundary/) {
-# print DEBUG "Entered header\n";
- $inheader = 1;
- $itemname = "";
- next;
- }
+ if ( $fieldname ) {
+ chomp($fieldvalue);
+ $fieldvalue =~ s/\r$//;
+ if ( defined $::FORM{$fieldname} ) {
+ $::FORM{$fieldname} .= $fieldvalue;
+ push @{$::MFORM{$fieldname}}, $fieldvalue;
+ } else {
+ $::FORM{$fieldname} = $fieldvalue;
+ $::MFORM{$fieldname} = [$fieldvalue];
+ }
+ }
- if ($inheader) {
+ $inheader = 1;
+ $fieldname = "";
+ $fieldvalue = "";
+
+ # If the current input line is a header line, look for a blank line
+ # (meaning the end of the headers), a Content-Disposition header
+ # (containing the field name and, for uploaded file parts, the file
+ # name), or a Content-Type header (containing the content type for
+ # file parts).
+ } elsif ( $inheader ) {
if (m/^\s*$/) {
$inheader = 0;
-# print DEBUG "left header\n";
- $::FORM{$itemname} = "";
- }
- if (m/^Content-Disposition:\s*form-data\s*;\s*name\s*=\s*"([^\"]+)"/i) {
- $itemname = $1;
-# print DEBUG "Found itemname $itemname\n";
+ } elsif (m/^Content-Disposition:\s*form-data\s*;\s*name\s*=\s*"([^\"]+)"/i) {
+ $fieldname = $1;
if (m/;\s*filename\s*=\s*"([^\"]+)"/i) {
- $::FILENAME{$itemname} = $1;
+ $::FILE{$fieldname}->{'filename'} = $1;
}
+ } elsif ( m|^Content-Type:\s*([^/]+/[^\s;]+)|i ) {
+ $::FILE{$fieldname}->{'contenttype'} = $1;
}
-
- next;
+
+ # If the current input line is neither a boundary line nor a header,
+ # it must be part of the field value, so append it to the value.
+ } else {
+ $fieldvalue .= $_;
}
- $::FORM{$itemname} .= $_;
- }
- delete $::FORM{""};
- # Get rid of trailing newlines.
- foreach my $i (keys %::FORM) {
- chomp($::FORM{$i});
- $::FORM{$i} =~ s/\r$//;
}
}