Skip to content

Commit

Permalink
fixed small URL escaping bug in Mojo::UserAgent::Transactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 8, 2012
1 parent f2327dd commit b2e89f7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
2.48 2012-02-08 00:00:00
- Improved documentation.
- Improved tests.
- Fixed small URL escaping bug in Mojo::UserAgent::Transactor.
- Fixed small MIME::Base64 and MIME::QuotedPrint related bugs in
Mojo::Util. (sestegra, sri)

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -225,7 +225,7 @@ sub tx {
$req->method(shift);
my $url = shift;
$url = "http://$url" unless $url =~ m#^/|\://#;
$req->url->parse($url);
ref $url ? $req->url($url) : $req->url->parse($url);

# Callback
my $cb = pop @_ if ref $_[-1] && ref $_[-1] eq 'CODE';
Expand Down
22 changes: 15 additions & 7 deletions t/mojo/path.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 179;
use Test::More tests => 184;

# "This is the greatest case of false advertising I’ve seen since I sued the
# movie 'The Never Ending Story.'"
Expand Down Expand Up @@ -165,12 +165,12 @@ ok !$path->contains('/♥.html'), 'does not contain path';

# Empty path elements
$path = Mojo::Path->new('//');
is "$path", '//';
is "$path", '//', 'rigth result';
is $path->parts->[0], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new('/foo//bar/23/');
is "$path", '/foo//bar/23/';
is "$path", '/foo//bar/23/', 'rigth result';
is $path->parts->[0], 'foo', 'right part';
is $path->parts->[1], '', 'right part';
is $path->parts->[2], 'bar', 'right part';
Expand All @@ -179,7 +179,7 @@ is $path->parts->[4], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new('//foo/bar/23/');
is "$path", '//foo/bar/23/';
is "$path", '//foo/bar/23/', 'rigth result';
is $path->parts->[0], '', 'right part';
is $path->parts->[1], 'foo', 'right part';
is $path->parts->[2], 'bar', 'right part';
Expand All @@ -188,7 +188,7 @@ is $path->parts->[4], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new('/foo///bar/23/');
is "$path", '/foo///bar/23/';
is "$path", '/foo///bar/23/', 'rigth result';
is $path->parts->[0], 'foo', 'right part';
is $path->parts->[1], '', 'right part';
is $path->parts->[2], '', 'right part';
Expand All @@ -198,7 +198,7 @@ is $path->parts->[5], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new('///foo/bar/23/');
is "$path", '///foo/bar/23/';
is "$path", '///foo/bar/23/', 'rigth result';
is $path->parts->[0], '', 'right part';
is $path->parts->[1], '', 'right part';
is $path->parts->[2], 'foo', 'right part';
Expand All @@ -208,7 +208,7 @@ is $path->parts->[5], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';
$path = Mojo::Path->new('///foo///bar/23///');
is "$path", '///foo///bar/23///';
is "$path", '///foo///bar/23///', 'rigth result';
is $path->parts->[0], '', 'right part';
is $path->parts->[1], '', 'right part';
is $path->parts->[2], 'foo', 'right part';
Expand All @@ -221,3 +221,11 @@ is $path->parts->[8], '', 'right part';
is $path->parts->[9], undef, 'no part';
ok $path->leading_slash, 'has leading slash';
ok $path->trailing_slash, 'has trailing slash';

# Escaped slash
$path = Mojo::Path->new->parts(['foo/bar']);
is $path->parts->[0], 'foo/bar', 'right part';
is $path->parts->[1], undef, 'no part';
is "$path", 'foo%2Fbar', 'rigth result';
is $path->to_string, 'foo%2Fbar', 'rigth result';
is $path->to_abs_string, '/foo%2Fbar', 'rigth result';
12 changes: 11 additions & 1 deletion t/mojo/transactor.t
@@ -1,9 +1,10 @@
use Mojo::Base -strict;

use Test::More tests => 175;
use Test::More tests => 179;

use File::Spec;
use FindBin;
use Mojo::URL;

# "Once the government approves something, it's no longer immoral!"
use_ok 'Mojo::UserAgent::Transactor';
Expand All @@ -14,6 +15,15 @@ my $tx = $t->tx(GET => 'mojolicio.us/foo.html?bar=baz');
is $tx->req->url->to_abs, 'http://mojolicio.us/foo.html?bar=baz', 'right URL';
is $tx->req->method, 'GET', 'right method';

# GET with escaped slash
my $url = Mojo::URL->new('http://mojolicio.us');
$url->path->parts(['foo/bar']);
$tx = $t->tx(GET => $url);
is $tx->req->url->to_string, $url->to_string, 'URLs are equal';
is $tx->req->url->path->to_string, $url->path->to_string, 'paths are equal';
is $tx->req->url->path->to_string, 'foo%2Fbar', 'right path';
is $tx->req->method, 'GET', 'right method';

# POST with header
$tx = $t->tx(POST => 'https://mojolicio.us', {Expect => 'nothing'});
is $tx->req->url->to_abs, 'https://mojolicio.us', 'right URL';
Expand Down

0 comments on commit b2e89f7

Please sign in to comment.