Skip to content

Commit

Permalink
fix url_for to handle paths without trailing slash correctly in embed…
Browse files Browse the repository at this point in the history
…ded applications
  • Loading branch information
kraih committed Feb 16, 2015
1 parent 581885e commit d9ea48e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

5.80 2015-02-16
- Fixed url_for to handle paths without trailing slash correctly in embedded
applications.

5.79 2015-02-13
- Fixed bug in Mojo::Reactor::Poll that caused excessive idle CPU usage.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -334,7 +334,7 @@ sub url_for {
# Relative URL
my $path = $url->path;
if ($target =~ m!^/!) {
if (my $prefix = $self->stash->{path}) {
if (defined(my $prefix = $self->stash->{path})) {
my $real = $req->url->path->to_route;
$real =~ s!/?\Q$prefix\E$!$target!;
$target = $real;
Expand Down
24 changes: 24 additions & 0 deletions t/mojolicious/embedded_lite_app.t
Expand Up @@ -181,6 +181,18 @@ too!works!!!Mojolicious::Plugin::Config::Sandbox
</form>
EOF

# Template from myapp.pl (no trailing slash)
$t->get_ok('/x/1')->status_is(200)->content_is(<<'EOF');
myapp
works ♥!Insecure!Insecure!
too!works!!!Mojolicious::Plugin::Config::Sandbox
<a href="/x/1/">Test</a>
<form action="/x/1/%E2%98%83">
<input type="submit" value="☃">
</form>
EOF

# Static file from myapp.pl
$t->get_ok('/x/1/index.html')->status_is(200)
->content_is("External static file!\n");
Expand Down Expand Up @@ -214,6 +226,18 @@ too!works!!!Mojolicious::Plugin::Config::Sandbox
</form>
EOF

# Template from myapp.pl with Unicode prefix (no trailing slash)
$t->get_ok('/x/♥')->status_is(200)->content_is(<<'EOF');
myapp
works ♥!Insecure!Insecure!
too!works!!!Mojolicious::Plugin::Config::Sandbox
<a href="/x/%E2%99%A5/">Test</a>
<form action="/x/%E2%99%A5/%E2%98%83">
<input type="submit" value="☃">
</form>
EOF

# Static file from myapp.pl with Unicode prefix
$t->get_ok('/x/♥/index.html')->status_is(200)
->content_is("External static file!\n");
Expand Down

0 comments on commit d9ea48e

Please sign in to comment.