Subject: | Support for uploading empty files |
Parsing an upload of an empty (zero-length) file using multipart fails.
Patch and test cases attached.
Subject: | http-body-empty-uploads.diff |
=== lib/HTTP/Body/MultiPart.pm
==================================================================
--- lib/HTTP/Body/MultiPart.pm (revision 62876)
+++ lib/HTTP/Body/MultiPart.pm (local)
@@ -257,16 +257,17 @@
sub handler {
my ( $self, $part ) = @_;
+ my $disposition = $part->{headers}->{'Content-Disposition'};
+ my ($name) = $disposition =~ / name="?([^\";]+)"?/;
+ my ($filename) = $disposition =~ / filename="?([^\"]+)"?/;
+
# skip parts without content
- if ( $part->{done} && $part->{size} == 0 ) {
+ if ( $part->{done} && $part->{size} == 0 && !$filename) {
return 0;
}
unless ( exists $part->{name} ) {
- my $disposition = $part->{headers}->{'Content-Disposition'};
- my ($name) = $disposition =~ / name="?([^\";]+)"?/;
- my ($filename) = $disposition =~ / filename="?([^\"]+)"?/;
$part->{name} = $name;
$part->{filename} = $filename;
=== t/data/multipart/001-content.dat
==================================================================
--- t/data/multipart/001-content.dat (revision 62876)
+++ t/data/multipart/001-content.dat (local)
@@ -60,4 +60,9 @@
print "Hello World :)\n";
+------------0xKhTmLbOuNdArY
+Content-Disposition: form-data; name="upload3"; filename="blank.pl"
+Content-Type: application/octet-stream
+
+
------------0xKhTmLbOuNdArY--
=== t/data/multipart/001-headers.yml
==================================================================
--- t/data/multipart/001-headers.yml (revision 62876)
+++ t/data/multipart/001-headers.yml (local)
@@ -1,4 +1,4 @@
---
-Content-Length: 1559
+Content-Length: 1701
Content-Type: multipart/form-data; boundary=----------0xKhTmLbOuNdArY
User-Agent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'
=== t/data/multipart/001-results.yml
==================================================================
--- t/data/multipart/001-results.yml (revision 62876)
+++ t/data/multipart/001-results.yml (local)
@@ -27,3 +27,10 @@
Content-Type: application/octet-stream
name: upload2
size: 71
+ upload3:
+ filename: blank.pl
+ headers:
+ Content-Disposition: form-data; name="upload3"; filename="blank.pl"
+ Content-Type: application/octet-stream
+ name: upload3
+ size: 0