Skip to content

Commit

Permalink
fixed "0" value bug in Mojo::UserAgent::Transactor (closes #641)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 2, 2014
1 parent efd9831 commit dbe303b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@
Mojolicious::Plugin::DefaultHelpers.
- Improved error method in Mojolicious::Validator::Validation to return
field names when called without arguments.
- Fixed "0" value bug in Mojo::UserAgent::Transactor.

5.10 2014-06-28
- Added cleanup attribute to Mojo::Server::Prefork.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -208,7 +208,7 @@ sub _multipart {
if (my $file = delete $value->{file}) {
$file = Mojo::Asset::File->new(path => $file) unless ref $file;
$part->asset($file);
$value->{filename} ||= basename $file->path
$value->{filename} //= basename $file->path
if $file->isa('Mojo::Asset::File');
}

Expand All @@ -218,7 +218,7 @@ sub _multipart {
}

# Filename and headers
$filename = delete $value->{filename} || $name;
$filename = delete $value->{filename} // $name;
$filename = encode $charset, $filename if $charset;
$headers->from_hash($value);
}
Expand All @@ -232,7 +232,7 @@ sub _multipart {
# Content-Disposition
$name = encode $charset, $name if $charset;
my $disposition = qq{form-data; name="$name"};
$disposition .= qq{; filename="$filename"} if $filename;
$disposition .= qq{; filename="$filename"} if defined $filename;
$headers->content_disposition($disposition);
}
}
Expand Down
14 changes: 7 additions & 7 deletions t/mojo/transactor.t
Expand Up @@ -249,22 +249,22 @@ ok !$tx->req->content->parts->[0]->asset->is_file, 'stored in memory';
ok !$tx->req->content->parts->[0]->asset->auto_upgrade, 'no upgrade';
is $tx->req->content->parts->[1], undef, 'no more parts';

# Multipart form with filename
# Multipart form with filename ("0")
$tx = $t->tx(POST => 'http://example.com/foo' => form =>
{myzip => {content => 'whatever', filename => 'foo.zip'}});
{0 => {content => 'whatever', filename => '0'}});
is $tx->req->url->to_abs, 'http://example.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/foo\.zip/, 'right "Content-Disposition" value';
like $tx->req->content->parts->[0]->headers->content_disposition, qr/0/,
'right "Content-Disposition" value';
ok !$tx->req->content->parts->[0]->headers->header('filename'),
'no "filename" header';
is $tx->req->content->parts->[0]->asset->slurp, 'whatever', 'right part';
is $tx->req->content->parts->[1], undef, 'no more parts';
is $tx->req->upload('myzip')->filename, 'foo.zip', 'right filename';
is $tx->req->upload('myzip')->size, 8, 'right size';
is $tx->req->upload('myzip')->slurp, 'whatever', 'right content';
is $tx->req->upload('0')->filename, '0', 'right filename';
is $tx->req->upload('0')->size, 8, 'right size';
is $tx->req->upload('0')->slurp, 'whatever', 'right content';

# Multipart form with asset and filename (UTF-8)
my $snowman = encode 'UTF-8', '';
Expand Down

0 comments on commit dbe303b

Please sign in to comment.