Lite.pm (CGI-Lite-3.01) | : | Lite.pm (CGI-Lite-3.02) | ||
---|---|---|---|---|
##++ | ##++ | |||
## CGI Lite v3.01 | ## CGI Lite v3.02 | |||
## | ## | |||
## see separate CHANGES file for detailed history | ## see separate CHANGES file for detailed history | |||
## | ## | |||
## Changes in versions 2.03 and newer copyright (c) 2014-2015 Pete Houston | ## Changes in versions 2.03 and newer copyright (c) 2014-2015 Pete Houston | |||
## | ## | |||
## Copyright (c) 1995, 1996, 1997 by Shishir Gundavaram | ## Copyright (c) 1995, 1996, 1997 by Shishir Gundavaram | |||
## All Rights Reserved | ## All Rights Reserved | |||
## | ## | |||
## Permission to use, copy, and distribute is hereby granted, | ## Permission to use, copy, and distribute is hereby granted, | |||
## providing that the above copyright notice and this permission | ## providing that the above copyright notice and this permission | |||
skipping to change at line 591 | skipping to change at line 591 | |||
##++ | ##++ | |||
## Global Variables | ## Global Variables | |||
##-- | ##-- | |||
BEGIN { | BEGIN { | |||
our @ISA = 'Exporter'; | our @ISA = 'Exporter'; | |||
our @EXPORT = qw/browser_escape url_encode url_decode is_dangerous/; | our @EXPORT = qw/browser_escape url_encode url_decode is_dangerous/; | |||
} | } | |||
our $VERSION = '3.01'; | our $VERSION = '3.02'; | |||
##++ | ##++ | |||
## Start | ## Start | |||
##-- | ##-- | |||
sub new | sub new | |||
{ | { | |||
my $class = shift; | my $class = shift; | |||
my $self = { | my $self = { | |||
skipping to change at line 1148 | skipping to change at line 1148 | |||
} | } | |||
##++ | ##++ | |||
## Methods dealing with multipart data | ## Methods dealing with multipart data | |||
##-- | ##-- | |||
sub _parse_multipart_data | sub _parse_multipart_data | |||
{ | { | |||
my ($self, $total_bytes, $boundary) = @_; | my ($self, $total_bytes, $boundary) = @_; | |||
my $files = {}; | my $files = {}; | |||
$boundary = quotemeta ($boundary); | my $boundary_re = qr/(.*?)((?:\015?\012)?-* | |||
\Q$boundary\E | ||||
-*[\015\012]*)(?=(.*))/xs; | ||||
eval { | eval { | |||
my ($seen, $buffer_size, $byte_count, $platform, | my ($seen, $buffer_size, $byte_count, $platform, | |||
$eol, $handle, $directory, $bytes_left, | $eol, $handle, $directory, $bytes_left, | |||
$new_data, $old_data, $this_boundary, $current_buffer , | $new_data, $old_data, $this_boundary, $current_buffer , | |||
$changed, $store, $disposition, $headers, | $changed, $store, $disposition, $headers, | |||
$mime_type, $convert, $field, $file, | $mime_type, $convert, $field, $file, | |||
$new_name, $full_path | $new_name, $full_path | |||
); | ); | |||
$seen = {}; | $seen = {}; | |||
$buffer_size = $self->{buffer_size}; | $buffer_size = $self->{buffer_size}; | |||
$byte_count = 0; | $byte_count = 0; | |||
$platform = $self->{platform}; | $platform = $self->{platform}; | |||
$eol = $self->{eol}->{$platform}; | $eol = $self->{eol}->{$platform}; | |||
$directory = $self->{multipart_dir}; | $directory = $self->{multipart_dir}; | |||
$bytes_left = $total_bytes; | ||||
while (1) { | while ($bytes_left) { | |||
if ( ($byte_count < $total_bytes) | if ($byte_count < $total_bytes) { | |||
&& (length ($current_buffer || '') < ($buffer_siz | ||||
e * 2))) { | ||||
$bytes_left = $total_bytes - $byte_count; | $bytes_left = $total_bytes - $byte_count; | |||
$buffer_size = $bytes_left if ($bytes_left < $buf fer_size); | $buffer_size = $bytes_left if ($bytes_left < $buf fer_size); | |||
read (STDIN, $new_data, $buffer_size); | read (STDIN, $new_data, $buffer_size); | |||
$self->_error ("Oh, Oh! I'm upset! Can't read wha t I want.") | $self->_error ("Oh, Oh! I'm upset! Can't read wha t I want.") | |||
if (length ($new_data) != $buffer_size); | if (length ($new_data) != $buffer_size); | |||
$byte_count += $buffer_size; | $byte_count += $buffer_size; | |||
skipping to change at line 1203 | skipping to change at line 1205 | |||
$changed = 0; | $changed = 0; | |||
##++ | ##++ | |||
## When Netscape Navigator creates a random boundary str ing, you | ## When Netscape Navigator creates a random boundary str ing, you | |||
## would expect it to pass that _same_ value in the envi ronment | ## would expect it to pass that _same_ value in the envi ronment | |||
## variable CONTENT_TYPE, but it does not! Instead, it p asses a | ## variable CONTENT_TYPE, but it does not! Instead, it p asses a | |||
## value that has the first two characters ("--") missin g. | ## value that has the first two characters ("--") missin g. | |||
##-- | ##-- | |||
if ($current_buffer =~ | if ($current_buffer =~ $boundary_re) { | |||
/(.*?)((?:\015?\012)?-*$boundary-*[\015\012]*)(?= | ||||
(.*))/os) { | ||||
($store, $this_boundary, $old_data) = ($1, $2, $3 ); | ($store, $this_boundary, $old_data) = ($1, $2, $3 ); | |||
if ($current_buffer =~ | if ($current_buffer =~ | |||
/[Cc]ontent-[Dd]isposition: ([^\015\012]+ )\015?\012 # Disposition | /[Cc]ontent-[Dd]isposition: ([^\015\012]+ )\015?\012 # Disposition | |||
(?:([A-Za-z].*?)(?:\015?\012))? # Headers | (?:([A-Za-z].*?)(?:\015?\012))? # Headers | |||
(?:\015?\012) # End | (?:\015?\012) # End | |||
(?=(.*)) # Other Data | (?=(.*)) # Other Data | |||
/xs | /xs | |||
) { | ) { | |||
skipping to change at line 1283 | skipping to change at line 1284 | |||
$files->{$new_name} = $full_path; | $files->{$new_name} = $full_path; | |||
} | } | |||
} elsif ($byte_count < $total_bytes) { | } elsif ($byte_count < $total_bytes) { | |||
$old_data = $this_boundary . $old_data; | $old_data = $this_boundary . $old_data; | |||
} | } | |||
} elsif ($old_data) { | } elsif ($old_data) { | |||
$store = $old_data; | $store = $old_data; | |||
$old_data = $new_data; | $old_data = $new_data; | |||
} else { | ||||
$store = $current_buffer; | ||||
$current_buffer = $new_data; | ||||
} | } | |||
unless ($changed) { | unless ($changed) { | |||
$self->_store ($platform, $file, $convert, $handl e, $eol, | $self->_store ($platform, $file, $convert, $handl e, $eol, | |||
$field, \$store, $seen); | $field, \$store, $seen); | |||
} | } | |||
} | } | |||
close ($handle) if ($handle and fileno ($handle)); | close ($handle) if ($handle and fileno ($handle)); | |||
skipping to change at line 1312 | skipping to change at line 1309 | |||
} | } | |||
sub _store | sub _store | |||
{ | { | |||
my ($self, $platform, $file, $convert, $handle, $eol, $field, $info, $see n) | my ($self, $platform, $file, $convert, $handle, $eol, $field, $info, $see n) | |||
= @_; | = @_; | |||
if ($file) { | if ($file) { | |||
if ($convert) { | if ($convert) { | |||
if ($platform eq 'PC') { | if ($platform eq 'PC') { | |||
$$info =~ s/\015(?=[^\012])|(?<=[^\015])\012/$eol /og; | $$info =~ s/\015(?!\012)|(?<!\015)\012/$eol/og; | |||
} else { | } else { | |||
$$info =~ s/\015\012/$eol/og; | $$info =~ s/\015\012/$eol/og; | |||
$$info =~ s/\015/$eol/og if ($platform ne 'Mac'); | $$info =~ s/\015/$eol/og if ($platform ne 'Mac'); | |||
$$info =~ s/\012/$eol/og if ($platform ne 'Unix') ; | $$info =~ s/\012/$eol/og if ($platform ne 'Unix') ; | |||
} | } | |||
} | } | |||
binmode $handle; | binmode $handle; | |||
print $handle $$info; | print $handle $$info; | |||
End of changes. 8 change blocks. | ||||
15 lines changed or deleted | 10 lines changed or added |