Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix url_for to handle fragments correctly
  • Loading branch information
kraih committed Jan 10, 2016
1 parent e9b5615 commit 1834915
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,5 @@

6.40 2016-01-10
6.40 2016-01-11
- Removed client_challenge, client_handshake and server_handshake methods from
Mojo::Transaction::WebSocket. (batman)
- Removed upgrade event from Mojo::Transaction::HTTP.
Expand All @@ -14,6 +14,7 @@
- Updated jQuery to version 2.2.0.
- Improve mtime attribute in Mojo::Asset::Memory to default to the value of
$^T.
- Fixed url_for to handle fragments correctly.

6.39 2016-01-03
- Updated links to Mojolicious website.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -295,7 +295,7 @@ sub url_for {

# Absolute URL
return $target if Scalar::Util::blessed $target && $target->isa('Mojo::URL');
return Mojo::URL->new($target) if $target =~ m!^(?:[^:/?#]+:|//)!;
return Mojo::URL->new($target) if $target =~ m!^(?:[^:/?#]+:|//|#)!;

# Base
my $url = Mojo::URL->new;
Expand Down Expand Up @@ -895,6 +895,7 @@ C<mojo.*> prefix are reserved for internal use.
my $url = $c->url_for('/index.html');
my $url = $c->url_for('//example.com/index.html');
my $url = $c->url_for('http://example.com/index.html');
my $url = $c->url_for('#whatever');
my $url = $c->url_for('mailto:sri@example.com');
Generate a portable L<Mojo::URL> object with base for a path, URL or route.
Expand Down
6 changes: 6 additions & 0 deletions t/mojolicious/tag_helper_lite_app.t
Expand Up @@ -92,6 +92,8 @@ $t->get_ok('/links')->status_is(200)->content_is(<<'EOF');
<a href="mailto:sri@example.com">Contact</a>
<a href="/links">Home</a>
<a href="/form/23" title="Foo">Foo</a>
<a href="#">Bar</a>
<a href="#baz">Baz</a>
<a href="/form/23" title="Foo">Foo</a>
EOF
$t->post_ok('/links')->status_is(200)->content_is(<<'EOF');
Expand All @@ -102,6 +104,8 @@ $t->post_ok('/links')->status_is(200)->content_is(<<'EOF');
<a href="mailto:sri@example.com">Contact</a>
<a href="/links">Home</a>
<a href="/form/23" title="Foo">Foo</a>
<a href="#">Bar</a>
<a href="#baz">Baz</a>
<a href="/form/23" title="Foo">Foo</a>
EOF

Expand Down Expand Up @@ -528,6 +532,8 @@ __DATA__
<%= link_to Contact => 'mailto:sri@example.com' %>
<%= link_to Home => 'links' %>
<%= link_to Foo => 'form', {test => 23}, title => 'Foo' %>
<%= link_to Bar => '#' %>
<%= link_to Baz => '#baz' %>
<%= link_to form => {test => 23} => (title => 'Foo') => begin %>Foo<% end %>
@@ script.html.ep
Expand Down

0 comments on commit 1834915

Please sign in to comment.