Skip to content

Commit

Permalink
a few more boundary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 30, 2012
1 parent 0432925 commit df375ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.53 2012-10-29
3.53 2012-10-30
- Improved documentation.
- Improved tests.

Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -39,9 +39,7 @@ sub build_boundary {
my $self = shift;

# Check for existing boundary
my $headers = $self->headers;
my $type = $headers->content_type || '';
$type =~ /boundary="?([^\s"]+)"?/i and return $1;
if (defined(my $boundary = $self->boundary)) { return $boundary }

# Generate and check boundary
my $boundary;
Expand All @@ -53,7 +51,8 @@ sub build_boundary {
}

# Add boundary to Content-Type header
$type =~ m!^(.*multipart/[^;]+)(.*)$!;
my $headers = $self->headers;
($headers->content_type || '') =~ m!^(.*multipart/[^;]+)(.*)$!;
my $before = $1 || 'multipart/mixed';
my $after = $2 || '';
$headers->content_type("$before; boundary=$boundary$after");
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/content.t
Expand Up @@ -29,6 +29,11 @@ ok $content->body_contains('foo'), 'content contains "foo"';
ok $content->body_contains('bar+'), 'content contains "bar+"';
ok $content->body_contains('.'), 'content contains "."';
ok $content->body_contains('.*?foo+'), 'content contains ".*?foo+"';
ok !$content->headers->content_type, 'no "Content-Type" header';
ok my $boundary = $content->build_boundary, 'boundary has been generated';
is $boundary, $content->boundary, 'same boundary';
is $content->headers->content_type, "multipart/mixed; boundary=$boundary",
'right "Content-Type" header';

# Dynamic content
$content = Mojo::Content::Single->new;
Expand Down

0 comments on commit df375ad

Please sign in to comment.