Skip to content

Commit

Permalink
fixed small bug in boundary and charset methods of Mojo::Content
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 18, 2011
1 parent b360e70 commit 6d7daa0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.29 2011-11-19 00:00:00
- Fixed small bug in boundary and charset methods of Mojo::Content.

2.28 2011-11-18 00:00:00
- Improved documentation.
- Fixed small IPv6 portabilty issue in Mojo::IOLoop::Client.
Expand Down
10 changes: 6 additions & 4 deletions lib/Mojo/Content.pm
Expand Up @@ -18,8 +18,9 @@ sub body_size { croak 'Method "body_size" not implemented by subclass' }

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

# "Operator! Give me the number for 911!"
Expand Down Expand Up @@ -70,8 +71,9 @@ sub build_headers {
}

sub charset {
(shift->headers->content_type || '') =~ /charset="?([^"\s;]+)"?/i;
return $1;
(shift->headers->content_type || '') =~ /charset="?([^"\s;]+)"?/i
and return $1;
return;
}

sub clone {
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Message.pm
Expand Up @@ -180,9 +180,9 @@ sub cookie {
sub dom {
my $self = shift;
return if $self->is_multipart;
my $dom =
$self->dom_class->new->charset($self->content->charset)
->parse($self->body);
my $dom = $self->dom_class->new;
$dom->charset($self->content->charset);
$dom->parse($self->body);
return @_ ? $dom->find(@_) : $dom;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -35,7 +35,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.28';
our $VERSION = '2.29';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
22 changes: 16 additions & 6 deletions t/mojo/request.t
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 912;
use Test::More tests => 916;

# "When will I learn?
# The answer to life's problems aren't at the bottom of a bottle,
Expand Down Expand Up @@ -280,16 +280,18 @@ is $req->body, '', 'no content';
# Parse HTTP 1.0 start line and headers, no body
$req = Mojo::Message::Request->new;
$req->parse("GET /foo/bar/baz.html HTTP/1.0\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Content-Type: text/plain;charset=UTF-8\x0d\x0a");
$req->parse("Content-Length: 0\x0d\x0a\x0d\x0a");
ok $req->is_finished, 'request is finished';
is $req->method, 'GET', 'right method';
is $req->version, '1.0', 'right version';
ok $req->at_least_version('0.9'), 'at least version 0.9';
ok !$req->at_least_version('1.2'), 'not version 1.2';
is $req->url, '/foo/bar/baz.html', 'right URL';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->content_length, 0, 'right "Content-Length" value';
is $req->headers->content_type, 'text/plain;charset=UTF-8',
'right "Content-Type" value';
is $req->headers->content_length, 0, 'right "Content-Length" value';
is $req->content->charset, 'UTF-8', 'right charset';

# Parse HTTP 1.0 start line and headers, no body (missing Content-Length)
$req = Mojo::Message::Request->new;
Expand Down Expand Up @@ -425,8 +427,8 @@ $req->content->on(read => sub { $body .= pop });
$req->parse('GET /foo/bar/baz.html?fo');
$req->parse("o=13#23 HTTP/1.0\x0d\x0aContent");
$req->parse('-Type: text/');
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell");
$req->parse("o World!\n1234\nlalalala\n");
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aH");
$req->parse("ello World!\n1234\nlalalala\n");
ok $req->is_finished, 'request is finished';
is $req->method, 'GET', 'right method';
is $req->version, '1.0', 'right version';
Expand Down Expand Up @@ -797,6 +799,7 @@ my $file = File::Spec->catfile(File::Temp::tempdir(CLEANUP => 1),
("MOJO_TMP." . time . ".txt"));
ok $req->upload('upload')->move_to($file), 'moved file';
ok unlink($file), 'unlinked file';
is $req->content->boundary, '----------0xKhTmLbOuNdArY', 'right boundary';

# Parse HTTP 1.1 multipart request (with callbacks and stream)
$req = Mojo::Message::Request->new;
Expand Down Expand Up @@ -1868,3 +1871,10 @@ ok $req->at_least_version('1.0'), 'at least version 1.0';
ok !$req->at_least_version('1.2'), 'not version 1.2';
is $req->url, '/perldoc?Mojo%3A%3AMessage%3A%3ARequest', 'right URL';
is $req->url->query->params->[0], 'Mojo::Message::Request', 'right value';

# Tainted environment
$req = Mojo::Message::Request->new;
"a" =~ /(.)/;
ok !$req->content->charset, 'no charset';
"a" =~ /(.)/;
ok !$req->content->boundary, 'no boundary';

0 comments on commit 6d7daa0

Please sign in to comment.