Skip to content

Commit

Permalink
fixed a few multipart form handling bugs (closes #642)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 3, 2014
1 parent 21157d4 commit f6d804a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.12 2014-07-03
- Fixed a few multipart form handling bugs.

5.11 2014-07-02
- Moved reverse_proxy attribute from Mojo::Server::Daemon to Mojo::Server.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Message.pm
Expand Up @@ -274,9 +274,9 @@ sub _parse_formdata {
}

next unless my $disposition = $part->headers->content_disposition;
my ($filename) = $disposition =~ /[; ]filename\s*=\s*"?((?:\\"|[^"])*)"?/i;
my ($filename) = $disposition =~ /[; ]filename="((?:\\"|[^"])*)"/;
next if $upload && !defined $filename || !$upload && defined $filename;
my ($name) = $disposition =~ /[; ]name\s*=\s*"?((?:\\"|[^";])+)"?/i;
my ($name) = $disposition =~ /[; ]name="((?:\\"|[^;"])*)"/;
if ($charset) {
$name = decode($charset, $name) // $name if $name;
$filename = decode($charset, $filename) // $filename if $filename;
Expand Down
8 changes: 4 additions & 4 deletions t/mojo/request.t
Expand Up @@ -1694,7 +1694,7 @@ is $req->param('Zuname'), '', 'right value';
is $req->param('Text'), '', 'right value';
is $req->content->parts->[0]->asset->slurp, 'T', 'right content';

# Chrome 30 multipart/form-data request (with quotation marks)
# Chrome 35 multipart/form-data request (with quotation marks)
$req = Mojo::Message::Request->new;
$req->parse("POST / HTTP/1.1\x0d\x0a");
$req->parse("Host: 127.0.0.1:3000\x0d\x0a");
Expand All @@ -1713,16 +1713,16 @@ $req->parse("Accept-Encoding: gzip,deflate,sdch\x0d\x0a");
$req->parse("Accept-Language: en-US,en;q=0.8\x0d\x0a\x0d\x0a");
$req->parse("------WebKitFormBoundaryMTelhBLWA9N3KXAR\x0d\x0a");
$req->parse('Content-Disposition: form-data; na');
$req->parse('me="foo \\%22bar%22 baz"; filename="fo\\%22o%22.txt"');
$req->parse('me="foo \\%22bar%22 baz\"; filename="fo\\%22o%22.txt\"');
$req->parse("\x0d\x0a\x0d\x0atest\x0d\x0a");
$req->parse("------WebKitFormBoundaryMTelhBLWA9N3KXAR--\x0d\x0a");
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/', 'right URL';
is $req->upload('foo \\%22bar%22 baz')->filename, 'fo\\%22o%22.txt',
is $req->upload('foo \\%22bar%22 baz\\')->filename, 'fo\\%22o%22.txt\\',
'right filename';
is $req->upload('foo \\%22bar%22 baz')->slurp, 'test', 'right content';
is $req->upload('foo \\%22bar%22 baz\\')->slurp, 'test', 'right content';

# Firefox 24 multipart/form-data request (with quotation marks)
$req = Mojo::Message::Request->new;
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/request_cgi.t
Expand Up @@ -443,8 +443,8 @@ is $req->content->progress, 0, 'right progress';
$req->parse("--8jXGX\x0d\x0a");
is $req->content->progress, 9, 'right progress';
$req->parse(
"Content-Disposition: Form-Data; Name = file; Filename = file.txt\x0d\x0a"
. "Content-Type: application/octet-stream\x0d\x0a\x0d\x0a");
"Content-Disposition: form-data; name=\"file\"; filename=\"file.txt\""
. "\x0d\x0aContent-Type: application/octet-stream\x0d\x0a\x0d\x0a");
is $req->content->progress, 117, 'right progress';
$req->parse('11023456789');
is $req->content->progress, 128, 'right progress';
Expand Down

0 comments on commit f6d804a

Please sign in to comment.