Skip to content

Commit

Permalink
fixed bug where Mojo::UserAgent::Transactor would escape Content-Disp…
Browse files Browse the repository at this point in the history
…osition values
  • Loading branch information
kraih committed Nov 29, 2012
1 parent c647259 commit 950424f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@

3.64 2012-11-29
- Improved documentation.
- Fixed bug where Mojo::UserAgent::Transactor would escape
Content-Disposition values.

3.63 2012-11-28
- Added support for smooth restarting to Morbo.
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -11,7 +11,7 @@ use Mojo::Parameters;
use Mojo::Transaction::HTTP;
use Mojo::Transaction::WebSocket;
use Mojo::URL;
use Mojo::Util qw(encode url_escape);
use Mojo::Util 'encode';

sub endpoint {
my ($self, $tx) = @_;
Expand Down Expand Up @@ -204,7 +204,6 @@ sub _multipart {
if (ref $values eq 'HASH') {
$filename = delete $values->{filename} || $name;
$filename = encode $encoding, $filename if $encoding;
$filename = url_escape $filename, '^A-Za-z0-9\-._~';
push @parts, $part->asset(delete $values->{file});
$headers->from_hash($values);
}
Expand All @@ -220,7 +219,6 @@ sub _multipart {

# Content-Disposition
$name = encode $encoding, $name if $encoding;
$name = url_escape $name, '^A-Za-z0-9\-._~';
my $disposition = qq{form-data; name="$name"};
$disposition .= qq{; filename="$filename"} if $filename;
$headers->content_disposition($disposition);
Expand Down
19 changes: 19 additions & 0 deletions t/mojo/transactor.t
@@ -1,10 +1,13 @@
use Mojo::Base -strict;

use utf8;

use Test::More;
use File::Spec::Functions 'catdir';
use FindBin;
use Mojo::URL;
use Mojo::UserAgent::Transactor;
use Mojo::Util 'encode';

# Simle GET
my $t = Mojo::UserAgent::Transactor->new;
Expand Down Expand Up @@ -184,6 +187,22 @@ like $tx->req->content->parts->[0]->headers->content_disposition,
is $tx->req->content->parts->[0]->asset->slurp, 'whatever', 'right part';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with filename (UTF-8)
my $snowman = encode 'UTF-8', '';
$tx = $t->form('http://kraih.com/foo' => 'UTF-8' =>
{'' => {content => 'snowman', filename => '☃.jpg'}});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'multipart/form-data',
'right "Content-Type" value';
like $tx->req->content->parts->[0]->headers->content_disposition,
qr/$snowman/, 'right "Content-Disposition" value';
is $tx->req->content->parts->[0]->asset->slurp, 'snowman', 'right part';
is $tx->req->content->parts->[1], undef, 'no more parts';
is $tx->req->upload('')->filename, '☃.jpg', 'right filename';
is $tx->req->upload('')->size, 7, 'right size';
is $tx->req->upload('')->slurp, 'snowman', 'right content';

# Simple endpoint
$tx = $t->tx(GET => 'mojolicio.us');
is(($t->endpoint($tx))[0], 'http', 'right scheme');
Expand Down

0 comments on commit 950424f

Please sign in to comment.