Skip to content

Commit

Permalink
fix trailing slash bug in Mojo::URL (closes #975)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 22, 2016
1 parent 503dec9 commit 2c139a0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -6,6 +6,7 @@
- Removed squish function from Mojo::Util.
- Removed support for smart whitespace trimming from all_text and text methods
in Mojo::DOM.
- Fixed trailing slash bug in Mojo::URL.
- Fixed a few whitespace bugs in Mojo::DOM.

6.66 2016-06-16
Expand Down
9 changes: 3 additions & 6 deletions lib/Mojo/URL.pm
Expand Up @@ -149,18 +149,15 @@ sub to_abs {
return $abs if $path->leading_slash;

# Inherit path
my $base_path = $base->path;
if (!@{$path->parts}) {
$path
= $abs->path($base_path->clone)->path->trailing_slash(0)->canonicalize;
$path = $abs->path($base->path->clone)->path->canonicalize;

# Query
return $abs if length $abs->query->to_string;
$abs->query($base->query->clone);
$abs->query($base->query->clone) unless length $abs->query->to_string;
}

# Merge paths
else { $abs->path($base_path->clone->merge($path)->canonicalize) }
else { $abs->path($base->path->clone->merge($path)->canonicalize) }

return $abs;
}
Expand Down
10 changes: 5 additions & 5 deletions t/mojo/request_cgi.t
Expand Up @@ -232,7 +232,7 @@ is $req->param('login'), 'test', 'right value';
is $req->param('password'), '111', 'right value';
is $req->param('edition'), 'db6d8b30-16df-4ecd-be2f-c8194f94e1f4',
'right value';
is $req->url->to_abs->to_string, 'http://test1/index.pl', 'right absolute URL';
is $req->url->to_abs->to_string, 'http://test1/index.pl/', 'right absolute URL';

# Parse Apache 2.2 (win32) CGI environment variables and body
$req = Mojo::Message::Request->new;
Expand Down Expand Up @@ -265,7 +265,7 @@ is $req->param('login'), 'test', 'right value';
is $req->param('password'), '111', 'right value';
is $req->param('edition'), 'db6d8b30-16df-4ecd-be2f-c8194f94e1f4',
'right value';
is $req->url->to_abs->to_string, 'http://test1/index.pl', 'right absolute URL';
is $req->url->to_abs->to_string, 'http://test1/index.pl/', 'right absolute URL';

# Parse Apache 2.2.14 CGI environment variables and body (root)
$req = Mojo::Message::Request->new;
Expand Down Expand Up @@ -307,7 +307,7 @@ is $req->version, '1.1', 'right version';
ok !$req->is_secure, 'not secure';
is $req->body, 'hello=world', 'right content';
is_deeply $req->param('hello'), 'world', 'right parameters';
is $req->url->to_abs->to_string, 'http://127.0.0.1:13028/upload',
is $req->url->to_abs->to_string, 'http://127.0.0.1:13028/upload/',
'right absolute URL';

# Parse Apache 2.2.11 CGI environment variables and body (HTTPS=ON)
Expand Down Expand Up @@ -411,7 +411,7 @@ is $req->url->base->path, '/test/index.cgi/', 'right base path';
is $req->version, '1.0', 'right version';
is $req->body, 'hello=world', 'right content';
is_deeply $req->param('hello'), 'world', 'right parameters';
is $req->url->to_abs->to_string, 'http://localhost/test/index.cgi',
is $req->url->to_abs->to_string, 'http://localhost/test/index.cgi/',
'right absolute URL';

# Parse Apache 2.2.9 CGI environment variables (root without PATH_INFO)
Expand All @@ -433,7 +433,7 @@ is $req->url->base->host, 'getmyapp.org', 'right base host';
is $req->url->path, '', 'no path';
is $req->url->base->path, '/cgi-bin/myapp/myapp.pl/', 'right base path';
is $req->version, '1.1', 'right version';
is $req->url->to_abs->to_string, 'http://getmyapp.org/cgi-bin/myapp/myapp.pl',
is $req->url->to_abs->to_string, 'http://getmyapp.org/cgi-bin/myapp/myapp.pl/',
'right absolute URL';

# Parse Apache mod_fastcgi CGI environment variables (multipart file upload)
Expand Down
6 changes: 6 additions & 0 deletions t/mojo/url.t
Expand Up @@ -262,6 +262,12 @@ is $url->to_abs, 'http://example.com/bar/foo?foo=bar#23',
'right absolute version';
is $url->to_abs->base, 'http://example.com/bar/baz/', 'right base';

# Absolute with query
$url = Mojo::URL->new('?foo=bar#23');
$url->base->parse('http://example.com/bar/baz/');
is $url->to_abs, 'http://example.com/bar/baz/?foo=bar#23',
'right absolute version';

# Clone (advanced)
$url = Mojo::URL->new(
'ws://sri:foobar@example.com:8080/test/index.html?monkey=biz&foo=1#23');
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/rebased_lite_app.t
Expand Up @@ -46,7 +46,7 @@ http://example.com/rebased/
<img src="/rebased/images/test.png">
<link href="//example.com/base.css" rel="stylesheet">
<a href="mailto:sri@example.com">Contact</a>
http://example.com/rebased
http://example.com/rebased/
http://example.com/rebased/foo
/rebased/foo
http://example.com/
Expand Down

0 comments on commit 2c139a0

Please sign in to comment.