HTTP::Body 0.7, patch to support 0-length uploads v0.7
Andy Grundman [Fri, 23 Mar 2007 17:39:37 +0000 (17:39 +0000)]
Changes
META.yml
lib/HTTP/Body.pm
lib/HTTP/Body/MultiPart.pm
t/data/multipart/001-content.dat
t/data/multipart/001-headers.yml
t/data/multipart/001-results.yml

diff --git a/Changes b/Changes
index 322ce06..3558455 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 This file documents the revision history for Perl extension HTTP::Body.
 
+0.7   2007-03-23 10:00:00
+        - Fixed parsing an empty (zero-length) file using multipart.
+          http://rt.cpan.org/NoAuth/Bug.html?id=25392
+
 0.6   2006-01-06 00:00:00
         - Fixed buffer bug in OctetStream, reported by Daisuke Murase <typester@cpan.org>.
         - Fixed YAML prereq, reported by Jess Robinson
index 66e2078..4cb6aae 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,14 +1,14 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         HTTP-Body
-version:      0.4
+version:      0.7
 version_from: lib/HTTP/Body.pm
 installdirs:  site
 requires:
     Carp:                          0
     File::Temp:                    0.14
     IO::File:                      0
-    YAML:                          0
+    YAML:                          0.39
 
 distribution_type: module
 generated_by: ExtUtils::MakeMaker version 6.17
index 13ae9c3..ac3d87a 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 
 use Carp       qw[ ];
 
-our $VERSION = 0.6;
+our $VERSION = 0.7;
 
 our $TYPES = {
     'application/octet-stream'          => 'HTTP::Body::OctetStream',
index 45569c3..83aa9df 100644 (file)
@@ -257,16 +257,17 @@ sub parse_body {
 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;
index c45f909..cd96556 100644 (file)
@@ -60,4 +60,9 @@ use warnings;
 print "Hello World :)\n";
 
 \r
+------------0xKhTmLbOuNdArY\r
+Content-Disposition: form-data; name="upload3"; filename="blank.pl"\r
+Content-Type: application/octet-stream\r
+\r
+\r
 ------------0xKhTmLbOuNdArY--\r
index e2f5998..e7cac31 100644 (file)
@@ -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'
index bd2e318..f7f3ee8 100644 (file)
@@ -27,3 +27,10 @@ upload:
       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