Skip to content

Commit

Permalink
fix bug where Mojolicious::Renderer would wrap text in layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 17, 2016
1 parent cf8fd09 commit dc8b5d0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

7.06 2016-09-08
7.06 2016-09-17
- Fixed bug where Mojolicious::Renderer would wrap text in layouts.
- Fixed a few test description encoding bugs in Test::Mojo.

7.05 2016-08-29
Expand Down
22 changes: 10 additions & 12 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -99,17 +99,16 @@ sub render {
# Data
return delete $stash->{data}, $options->{format} if defined $stash->{data};

# Text
return _maybe($options->{encoding}, delete $stash->{text}), $options->{format}
if defined $stash->{text};

# JSON
return encode_json(delete $stash->{json}), 'json' if exists $stash->{json};

# Text
my $output = delete $stash->{text};

# Template or templateless handler
unless (defined $output) {
$options->{template} //= $self->template_for($c);
return () unless $self->_render_template($c, \$output, $options);
}
$options->{template} //= $self->template_for($c);
return () unless $self->_render_template($c, \my $output, $options);

# Inheritance
my $content = $stash->{'mojo.content'} ||= {};
Expand All @@ -122,11 +121,8 @@ sub render {
$content->{content} //= $output if $output =~ /\S/;
}

# Encoding
$output = encode $options->{encoding}, $output
if !$string && $options->{encoding} && $output;

return $output, $options->{format};
return $string ? $output : _maybe($options->{encoding}, $output),
$options->{format};
}

sub template_for {
Expand Down Expand Up @@ -195,6 +191,8 @@ sub warmup {
}
}

sub _maybe { $_[0] ? encode @_ : $_[1] }

sub _next {
my $stash = shift;
return delete $stash->{extends} if $stash->{extends};
Expand Down
8 changes: 0 additions & 8 deletions t/mojo/user_agent_online.t
Expand Up @@ -189,14 +189,6 @@ is $tx->req->method, 'GET', 'right method';
is $tx->req->url, 'https://metacpan.org', 'right url';
is $tx->res->code, 200, 'right status';

# HTTPS request that requires SNI
SKIP: {
skip 'SNI support required!', 1 unless IO::Socket::SSL->can_client_sni;
$tx = $ua->get('https://cpanmin.us');
is $tx->res->code, 302, 'right status';
like $tx->res->headers->location, qr/github/, 'right "Location" header';
}

# Fresh user agent again
$ua = Mojo::UserAgent->new;

Expand Down
14 changes: 6 additions & 8 deletions t/mojolicious/lite_app.t
Expand Up @@ -133,7 +133,7 @@ any '/json_too' => {json => {hello => 'world'}};

get '/null/:null' => sub {
my $c = shift;
$c->render(text => $c->param('null'), layout => 'layout');
$c->render(text => $c->param('null'));
};

get '/action_template' => {controller => 'foo'} => sub {
Expand Down Expand Up @@ -284,12 +284,7 @@ get '/foo' => sub {
};

get '/layout' => sub {
shift->render(
text => 'Yea baby!',
layout => 'layout',
handler => 'epl',
title => 'Layout'
);
shift->render(layout => 'layout', handler => 'epl', title => 'Layout');
};

post '/template' => 'index';
Expand Down Expand Up @@ -622,7 +617,7 @@ $t->get_ok('/template.txt.epl')->status_is(404)

# Captured "0"
$t->get_ok('/null/0')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_like(qr/layouted 0/);
->header_is(Server => 'Mojolicious (Perl)')->content_is('0');

# Render action
$t->get_ok('/action_template')->status_is(200)
Expand Down Expand Up @@ -1103,6 +1098,9 @@ layouted <%== content %>
@@ layouts/app23.html.ep
app layout <%= content %><%= app->mode %>
@@ layout.html.epl
Yea baby!\
@@ app.html.ep
<% layout layout . 23; %><%= layout %>
Expand Down

0 comments on commit dc8b5d0

Please sign in to comment.