Skip to content

Commit

Permalink
Merge branch 'bugfix/deserialize-multipart-form'
Browse files Browse the repository at this point in the history
  • Loading branch information
cromedome committed Aug 1, 2023
2 parents ba11df9 + 9a504b7 commit 492a2a5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* GH #1663: Allow overriding of prefix in add_route (GeekRuthie)
* GH #1675: Stringify VERSION_FROM correctly in Makefile.PL (Jason
A. Crome)
* GH #1677: Don't deserialize multipart form data on post (Emil
Perhinschi)

[ ENHANCEMENTS ]
* PR #1682: Bump minimum version of Perl to 5.14 (Jason A. Crome)
Expand Down
1 change: 1 addition & 0 deletions lib/Dancer2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ We are also on IRC: #dancer on irc.perl.org.
Dinis Rebolo
dtcyganov
Elliot Holden
Emil Perhinschi
Erik Smit
Fayland Lam
ferki
Expand Down
9 changes: 9 additions & 0 deletions lib/Dancer2/Core/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ sub data { $_[0]->{'data'} ||= $_[0]->deserialize() }
sub deserialize {
my $self = shift;

# don't attempt to deserialize if the form is 'multipart/form-data'
if (
$self->content_type
&& $self->content_type =~ /^multipart\/form-data/i
) {
return;
}


my $serializer = $self->serializer
or return;

Expand Down
40 changes: 40 additions & 0 deletions t/request_multipart_formdata.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use strict;
use warnings;

use Test::More tests => 2;
use Plack::Test;
use HTTP::Request::Common;
use Ref::Util qw<is_coderef>;


{
package MyApp;

use Dancer2;
our $entity;

set engines => {
serializer => {
JSON => {
pretty => 1,
}
}
};
set serializer => 'JSON';

post '/' => sub {
template 'index' => { 'title' => 'test_uploads' };
};

}

my $app = MyApp->to_app;
ok( is_coderef($app), 'Got app' );

my $test = Plack::Test->create($app);

my $filename = 't/app.t';
my $res = $test->request( POST '/',
"Content-Type" => 'multipart/form-data',
Content => [ filename => [ $filename ] ] );
ok( $res->is_success, '[POST /] successful' );

0 comments on commit 492a2a5

Please sign in to comment.