From: Andy Grundman Date: Thu, 7 May 2009 15:41:40 +0000 (+0000) Subject: Fix multipart boundaries with commas X-Git-Tag: v1.06~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTTP-Body.git;a=commitdiff_plain;h=4f8ae3af480f22fc9c7d83361954f1ffacc0d193 Fix multipart boundaries with commas --- diff --git a/Changes b/Changes index 27e4208..402fe56 100644 --- 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(). diff --git a/lib/HTTP/Body.pm b/lib/HTTP/Body.pm index 459387c..5dd4f32 100644 --- a/lib/HTTP/Body.pm +++ b/lib/HTTP/Body.pm @@ -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', diff --git a/lib/HTTP/Body/MultiPart.pm b/lib/HTTP/Body/MultiPart.pm index 78212cf..1c185ab 100644 --- a/lib/HTTP/Body/MultiPart.pm +++ b/lib/HTTP/Body/MultiPart.pm @@ -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'"); } diff --git a/t/04multipart.t b/t/04multipart.t index 1b27ebd..5e57261 100644 --- a/t/04multipart.t +++ b/t/04multipart.t @@ -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 index 0000000..57f5cd9 --- /dev/null +++ b/t/data/multipart/013-content.dat @@ -0,0 +1,23 @@ +------------0x'K()h+T_m,L-b.O/u:N=d?ArY +Content-Disposition: form-data; name="text1" + +Ratione accusamus aspernatur aliquam +------------0x'K()h+T_m,L-b.O/u:N=d?ArY +Content-Disposition: form-data; name="text2" + + +------------0x'K()h+T_m,L-b.O/u:N=d?ArY +Content-Disposition: form-data; name="select" + +A +------------0x'K()h+T_m,L-b.O/u:N=d?ArY +Content-Disposition: form-data; name="select" + +B +------------0x'K()h+T_m,L-b.O/u:N=d?ArY +Content-Disposition: form-data; name="textarea" + +Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non. + +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. +------------0x'K()h+T_m,L-b.O/u:N=d?ArY-- diff --git a/t/data/multipart/013-headers.yml b/t/data/multipart/013-headers.yml new file mode 100644 index 0000000..9dc742e --- /dev/null +++ b/t/data/multipart/013-headers.yml @@ -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 index 0000000..eea2341 --- /dev/null +++ b/t/data/multipart/013-results.yml @@ -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."