Fix multipart boundaries with commas
Andy Grundman [Thu, 7 May 2009 15:41:40 +0000 (15:41 +0000)]
Changes
lib/HTTP/Body.pm
lib/HTTP/Body/MultiPart.pm
t/04multipart.t
t/data/multipart/013-content.dat [new file with mode: 0644]
t/data/multipart/013-headers.yml [new file with mode: 0644]
t/data/multipart/013-results.yml [new file with mode: 0644]

diff --git a/Changes b/Changes
index 27e4208..402fe56 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 This file documents the revision history for Perl extension HTTP::Body.
 
+1.06    
+        - Fixed parsing of multipart bodies with boundaries that contain commas.
+          (Tomas Doran, http://rt.cpan.org/Public/Bug/Display.html?id=41407)
+
 1.05    2008-12-01 17:15:00
         - Removed useless eval + require in new().
 
index 459387c..5dd4f32 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 
 use Carp       qw[ ];
 
-our $VERSION = '1.05';
+our $VERSION = '1.06';
 
 our $TYPES = {
     'application/octet-stream'          => 'HTTP::Body::OctetStream',
index 78212cf..1c185ab 100644 (file)
@@ -30,7 +30,7 @@ HTTP Body Multipart Parser.
 sub init {
     my $self = shift;
 
-    unless ( $self->content_type =~ /boundary=\"?([^\";,]+)\"?/ ) {
+    unless ( $self->content_type =~ /boundary=\"?([^\";]+)\"?/ ) {
         my $content_type = $self->content_type;
         Carp::croak("Invalid boundary in content_type: '$content_type'");
     }
index 1b27ebd..5e57261 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 98;
+use Test::More tests => 102;
 
 use Cwd;
 use HTTP::Body;
@@ -14,7 +14,7 @@ use File::Temp qw/ tempdir /;
 
 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
 
-for ( my $i = 1; $i <= 12; $i++ ) {
+for ( my $i = 1; $i <= 13; $i++ ) {
 
     my $test    = sprintf( "%.3d", $i );
     my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
@@ -47,7 +47,8 @@ for ( my $i = 1; $i <= 12; $i++ ) {
 
     is_deeply( $body->body, $results->{body}, "$test MultiPart body" );
     is_deeply( $body->param, $results->{param}, "$test MultiPart param" );
-    is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" );
+    is_deeply( $body->upload, $results->{upload}, "$test MultiPart upload" )
+        if $results->{upload};
     cmp_ok( $body->state, 'eq', 'done', "$test MultiPart state" );
     cmp_ok( $body->length, '==', $body->content_length, "$test MultiPart length" );
     
diff --git a/t/data/multipart/013-content.dat b/t/data/multipart/013-content.dat
new file mode 100644 (file)
index 0000000..57f5cd9
--- /dev/null
@@ -0,0 +1,23 @@
+------------0x'K()h+T_m,L-b.O/u:N=d?ArY\r
+Content-Disposition: form-data; name="text1"\r
+\r
+Ratione accusamus aspernatur aliquam\r
+------------0x'K()h+T_m,L-b.O/u:N=d?ArY\r
+Content-Disposition: form-data; name="text2"\r
+\r
+\r
+------------0x'K()h+T_m,L-b.O/u:N=d?ArY\r
+Content-Disposition: form-data; name="select"\r
+\r
+A\r
+------------0x'K()h+T_m,L-b.O/u:N=d?ArY\r
+Content-Disposition: form-data; name="select"\r
+\r
+B\r
+------------0x'K()h+T_m,L-b.O/u:N=d?ArY\r
+Content-Disposition: form-data; name="textarea"\r
+\r
+Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r
+\r
+Molestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa.\r
+------------0x'K()h+T_m,L-b.O/u:N=d?ArY--\r
diff --git a/t/data/multipart/013-headers.yml b/t/data/multipart/013-headers.yml
new file mode 100644 (file)
index 0000000..9dc742e
--- /dev/null
@@ -0,0 +1,4 @@
+---
+Content-Length: 900
+Content-Type: multipart/form-data; boundary=----------0x'K()h+T_m,L-b.O/u:N=d?ArY
+User-Agent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'
diff --git a/t/data/multipart/013-results.yml b/t/data/multipart/013-results.yml
new file mode 100644 (file)
index 0000000..eea2341
--- /dev/null
@@ -0,0 +1,9 @@
+---
+body: ~
+param:
+  select:
+    - A
+    - B
+  text1: Ratione accusamus aspernatur aliquam
+  text2: ""
+  textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."