Skip to content

Commit

Permalink
fixed multipart boundary detection bug in Mojo::Content
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 13, 2012
1 parent e1c0194 commit de3d701
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,7 +1,8 @@

3.66 2012-12-11
3.66 2012-12-13
- Improved documentation.
- Improved tests.
- Fixed multipart boundary detection bug in Mojo::Content.

3.65 2012-12-09
- Added upgrade method to Mojo::UserAgent::Transactor.
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/Content.pm
Expand Up @@ -17,8 +17,9 @@ sub body_contains {
sub body_size { croak 'Method "body_size" not implemented by subclass' }

sub boundary {
my $type = shift->headers->content_type || '';
$type =~ m!multipart.*boundary="?([a-zA-Z0-9'(),.:?\-_+/]+)!i and return $1;
return undef unless my $type = shift->headers->content_type;
$type =~ m!multipart.*boundary=(?:"([^"]+)"|([\w'(),.:?\-+/]+))!i
and return $1 // $2;
return undef;
}

Expand Down
6 changes: 6 additions & 0 deletions t/mojo/content.t
Expand Up @@ -56,10 +56,16 @@ is $content->build_body,

# Multipart boundary detection
$content = Mojo::Content::MultiPart->new;
is $content->boundary, undef, 'no boundary';
$content->headers->content_type(
'multipart/form-data; boundary="azAZ09\'(),.:?-_+/"');
is $content->boundary, "azAZ09\'(),.:?-_+/", 'right boundary';
is $content->boundary, $content->build_boundary, 'same boundary';
$content->headers->content_type('multipart/form-data');
is $content->boundary, undef, 'no boundary';
$content->headers->content_type('multipart/form-data; boundary="foo bar baz"');
is $content->boundary, 'foo bar baz', 'right boundary';
is $content->boundary, $content->build_boundary, 'same boundary';

# Tainted environment
$content = Mojo::Content::MultiPart->new;
Expand Down

0 comments on commit de3d701

Please sign in to comment.